Hi Brendan, If you really, really want to work with the for() loop, then for(i in 1:10){ assign(paste("theta1_",i,sep=""),data.frame(scale(rnorm(250)))) assign(paste("theta2_",i,sep=""),data.frame(scale(rnorm(250)))) assign(paste("theta3_",i,sep=""), get(paste("theta1_",i,sep="")) + get(paste("theta2_",i,sep=""))) }
should work. I would rather prefer to work with list() as Duncan Murdoch and Dimitri Liakhovitski pointed out. See ?get for more details. HTH, Jorge On Mon, Apr 20, 2009 at 2:35 PM, Brendan Morse <morse.bren...@gmail.com>wrote: > Hi everyone, I am trying to calculate a particular variable (vector) from > some previously defined variables in a loop but I am having trouble > figuring > out how to get the loop to recognize that it should index for the > previously > defined objects. Here is a simplified version of what I am trying to do: > > for(i in 1:10){ > > assign(paste("theta1_",i,sep=""),data.frame(scale(rnorm(250)))) > > assign(paste("theta2_",i,sep=""),data.frame(scale(rnorm(250)))) > assign(paste("theta3_",i,sep=""),data.frame(theta1_i + > theta2_i) > } > > I am having trouble with getting it to recognize that theta3_i should be > calculated using theta1_i and theta2_i in the third line. In other words, > theta3_1 should equal theta1_1+theta2_1 whereas theta3_2 should equal > theta1_2+theta2_2 > > Any advice as to where I am losing this one? > > Thanks, > brendan > > [[alternative HTML version deleted]] > > ______________________________________________ > 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. > [[alternative HTML version deleted]] ______________________________________________ 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.