Re: [R] strange behaviour with loops and lists

2013-05-19 Thread Liviu Andronic
On Sun, May 19, 2013 at 7:02 PM, peter dalgaard wrote: > (The first example really had 2:3, not 5:7, right?) > Indeed. I simplified the example mid-email. > The essential bit is that to assign to the 2nd element of a list, it needs to > have at least two elements: > Thanks for the explanations.

Re: [R] strange behaviour with loops and lists

2013-05-19 Thread peter dalgaard
On May 19, 2013, at 18:08 , Liviu Andronic wrote: > Dear all, > I encountered this strange behaviour with loops and lists. Consider this: > xl <- list() > for(i in 5:7){##loop over numeric vector >xl[[i]] <- rnorm(i) > } >> xl > [[1]] > NULL > > [[2]] > [1] -0.4448192 -1.3395014 > > [[3]] >

Re: [R] strange behaviour with loops and lists

2013-05-19 Thread arun
Hi, xl<- vector("list",7) for(i in 5:7){##loop over numeric vector xl[[i]] <- rnorm(i)  }  xl #[[1]] #NULL # #[[2]] #NULL # #[[3]] #NULL # #[[4]] #NULL # #[[5]] #[1]  0.3266762  0.4316069  1.2290551 -0.6725783  1.6159861 # #[[6]] #[1] -2.8560618 -0.5694743 -0.7325862  1.6786160  0.3883842 -0.3