You can use scan with text :
balance.vars <- scan(text='a3 a4 a5_1 a5_2 a5_3 a6_1 a6_2 a6_3 a6_4 a6_5 a6_6 a8 a8_1 a8_2 a8_3 a9 a9_3 a10_1 a10_2 a10_3',what='char')
But I would avoid using a lot of shared variables like this. What not to use a vector or list? Perhaps if you better explain your workflow and what you want to do, we can offer more R-style.
You can also use paste to create a list like this:
paste(paste0('a',rep(3:10,each=3)),rep(0:3,8),sep='_')
EDIT after clarifying the OP, it seems he wants to filter out the data.frames variables.
varnames <- colnames(d)[grepl('^a[0-9]+(_[1-3])?',colnames(d))] formulas <- paste(varnames, "group", sep = " ~ ") res <- lapply(formulas, function(f) t.test(as.formula(f), data = d))
source share