Use eval
and quote
- I think that should allow you all of the flexibility you want:
for( SUBSET_VARIABLE in c(quote(gear), quote(carb)) ){
design <- subset( design , eval(SUBSET_VARIABLE) %in% 4 )
a <- svymean(~mpg, design)
}
Or if you want to have character strings as an input, you can use get
instead:
for( SUBSET_VARIABLE in c("gear", "carb") ){
design <- subset( design , get(SUBSET_VARIABLE) %in% 4 )
a <- svymean(~mpg, design)
}