I\'ve built an R function that uses the same explanatory variables on a range of columns. I\'ve used the glm
function, but now I need to do the same with
You need to use as.formula
to paste the appropriate columns for evaluation. I created a custom function for your case:
mysvy <- function(data, columns, ...) {
model <- lapply(as.list(columns), function(x) {
summary(svyglm(as.formula(paste0(names(data)[x], "~ell+meals+mobility")),
data = data, ...))
})
return(model)
}
Then you can run your your desired columns through the function.
# To run columns 13 - 15 and get the results into a list
results <- mysvy(apistrat, 13:15, design = dstrat)
# should return a list of 3. results[[1]] to see the first