I want to add columns to a survey.design created with the survey package, which can be done as following:
library(survey)
data(api)
dclus1 <- svydesign(id = ~dnum, weights = ~pw, data = apiclus1, fpc = ~fpc)
dclus2 <- transform(dclus1,
api00_b = api00 + 1)
svymean(~ api00, design = dclus2)
#> mean SE
#> api00 644.17 23.542
svymean(~ api00_b, design = dclus2)
#> mean SE
#> api00_b 645.17 23.542
For a more complex task, I need to create these variable names dynamically from external vectors. The following produces an error, but I think provides an illustration of what I want to achieve:
vars <- c("api00_a", "api00_b")
dclus2 <- transform(dclus1,
vars[[2]] = api00 + 1)
How could dynamic names for the new columns be implemented?