On Tue, Dec 29, 2009 at 6:31 PM, Lisa <lisa...@gmail.com> wrote: > > Thank you for your reply. But in the following case, “cat()” or “print()” > doesn’t work. > > data.frame(cbind(variable 1, variable 2, cat(paste("variable", x), "\n"))), > where x is a random number generated by other R script. > > Lisa
Yes, because you are Doing It Wrong. If you have data that is indexed by an integer, don't store it in variables called variable1, variable2 etc, because very soon you will be posting a message to R-help that is covered in the R FAQ... Store it in a list: v = list() v[[1]] = c(1,2,3,4,5) v[[2]] = c(4,5,6,7,8,9,9,9) then you can do v[[i]] for integer values of i. If you really really must get values of variable by name, perhaps because someone has given you a data file with variables called variable1 to variable99, then use the paste() construction together with the 'get' function: [ not tested, but should work ] > v1="99" > v2="102" > i=2 > get(paste("v",i,sep="")) [1] 102 Barry ______________________________________________ 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.