I am trying to figure out how to subset a survey design objects dynamically. I have structured my loop to send in character strings, and don't know how to remove the quotes so R reads it as a call.
I would like to loop through some like this (although this will obviously break because SUBSET_VARIABLE %in% 4 needs to be a call NOT a string. :
design <- svydesign( ~1 , weight = ~wt , data = mtcars )
for( SUBSET_VARIABLE in c("gear","carb") ){
design <- subset( design , SUBSET_VARIABLE %in% 4 )
a <- svymean(~mpg, design)
}
If possible I would like to avoid defining the statement in a paste function and than using eval( parse ( text = statement ) ) )
to execute it. Also, I would like to avoid using indexing, because I know that the subset method for survey.design
objects performs other tasks (see: getS3method("subset", "survey.design")
) and want to ensure that running the subset dynamically is exactly equivalent to using the subset function out of a loop. Thanks for any help you can provide
Matthew