better yet consider using a list:

> result <- list()
> individuals<-c("A","B","C","D")
> for (i in individuals) result[[i]] <- runif(10)
>
> result
$A
 [1] 0.61464497 0.55715954 0.32877732 0.45313145 0.50044097 0.18086636
0.52963060 0.07527575 0.27775593 0.21269952
$B
 [1] 0.28479048 0.89509410 0.44623532 0.77998489 0.88061903 0.41312421
0.06380848 0.33548749 0.72372595 0.33761533
$C
 [1] 0.6304141 0.8406146 0.8561317 0.3913593 0.3804939 0.8954454 0.6443158
0.7410786 0.6053034 0.9030816
$D
 [1] 0.2937302 0.1912601 0.8864509 0.5033395 0.8770575 0.1891936 0.7581031
0.7244989 0.9437248 0.5476466



On Thu, Mar 18, 2010 at 2:44 PM, 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<http://www.r-project.org/posting-guide.html>
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem that you are trying to solve?

        [[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.

Reply via email to