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.
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]]
>
#[1] -2.155804 1.780388
#
#[[3]]
#[1] 0.4192816 -1.0142512 -0.2125988
#
#[[4]]
#NULL
A.K.
- Original Message -
From: Liviu Andronic
To: "r-help@r-project.org Help"
Cc:
Sent: Sunday, May 19, 2013 12:08 PM
Subject: [R] strange behaviour with loops and lists
Dear all,
I encount
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]]
[1] 1.3214195 -1.2968560 -0.6327795
The above lists contained a NULL element
4 matches
Mail list logo