> indiv <- LETTERS[1:4] > for(i in seq_along(indiv)) assign(indiv[i], rnorm(10)) > A [1] -0.4140121 -0.8506043 -1.6704603 -0.3153009 1.9337826 -0.7736769 [7] -0.7906979 0.6925713 2.4678820 0.3889229 > B [1] -0.03521033 -0.01071611 -0.74209425 1.36974281 -1.22775441 0.29621976 [7] 0.28208192 -2.11044822 0.06657930 -0.18036208 > C [1] 0.8473888 0.5028627 2.4445523 0.6908494 2.2145275 -0.1589881 [7] -0.4135572 0.1313484 -0.8689705 -0.9267220 > D [1] -1.95177791 0.12495833 0.06847564 1.18425425 -1.16638075 -0.30278432 [7] -0.30268288 0.79178229 0.53021849 -0.32030840
HTH, Dennis On Thu, Mar 18, 2010 at 11:44 AM, Mark Na <mtb...@gmail.com> wrote: > Dear R helpers, > > I would like to write a loop that makes 4 objects (called A, B, C, and D) > each of which contains ten random numbers. > > This attempt: > > individuals<-c("A","B","C","D") > for(i in 1:length(individuals)) { > individuals[i]<-rnorm(10) > } > > > does not work because "individuals[i]" is not the proper way to extract > each > letter from the object called "individuals" (rather, it tries to assign the > random numbers to various positions within "individual") > > So, my question is, what should be to the left of the gets operator in the > third line? > > Many thanks, > > Mark Na > > [[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.