David Thanks for your suggestions. "Reproducible examples", my datasets are too big so I'm not sure what you would want to see. Anyway, does this help:
dataset: Perf_Index Age risk_score gender hight IQ ... 12 78 10 m 6 110 ... 10 77 9 f 6 97 ... 5 64 f 13 5 120 ... ... varslist: Perf_Index Age IQ ... As you suggested > str(varslist) 'data.frame': 1 obs. of 54 variables: $ V1 : Factor w/ 1 level "Perf_Index": 1 $ V2 : Factor w/ 1 level "Age": 1 $ V3 : Factor w/ 1 level "risk_score": 1 ... for (i in varslist){ v<-mean(Dataset[,i]) print(v) } gives: > source("/Users/jween/Desktop/test.R") [1] 20016.06 [1] 20016.06 [1] 20016.06 [1] 20016.06 [1] 20016.06 [1] 20016.06 ... 54 instances, the number of variables in varslist Not correct, obviously. I'm guessing I've not read varslist in correctly (I used read.table). Cheers Jon -- View this message in context: http://n4.nabble.com/variable-substitution-in-for-loops-tp1568384p1568429.html Sent from the R help mailing list archive at Nabble.com. ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.