[R] seq(along= surprise

Uwe Ligges ligges at statistik.tu-dortmund.de
Thu Feb 5 20:46:24 CET 2009



Uwe Ligges wrote:
> 
> 
> Kjetil Halvorsen wrote:
>> This surprised me:
>>
>>> reps <- 100
>>> sims <- list(length=reps)
>>> sims
>> $length
>> [1] 100
>>
>>> for(i in seq(along=sims))print(i)
>> [1] 1
>>
>> This is R 2.8.1.
> 
> 
> What is surprising?
> 
> sims is now a list that contains 1 element called "length" with a 
> numeric value of 100.
> Then seq(along=sims) is exactly 1, because sims has length 1.
> Hence i is printed once (1 iteration of the loop) and is 1 in the first 
> (and only) iteration.
> 
> Uwe

I should have added that you probably want

sims <- vector(mode="list", length=100)

Uwe


> 
> 
>> Kjetil
>>
>>     [[alternative HTML version deleted]]
>>
>> ______________________________________________
>> R-help at 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.
>




More information about the R-help mailing list