[R] create a list of vectors

Gabor Grothendieck ggrothendieck at gmail.com
Wed Mar 15 14:34:12 CET 2006


Try this:

L <- list(letters, head(LETTERS))
L[[2]][[4]] # D
sapply(L, length) # 26 6
L <- c(L, 1:4)
L[[3]][[2]] # 2
L <- c(L, list(1:5))


On 3/15/06, Arnau Mir Torres <arnau at mnm.uib.es> wrote:
> Hello.
>
> I want to create a list of vectors but each component of the list has a
> different length.
>
> For example:
>
> Example=list()
> Example=list(Example,c(1,2,3))
> Example=list(Example,c(11,12,13,14,15))
>
> If I want the first component of the Example list, I have to write:
>
> Example[[1]][[2]]. R responses
> 1 2 3
>
> The second component:
> Example[[2]]:
> 11 12 13 14 15
>
> If I iterate the previous example, Example=list(Example,c(...)) and I
> want the components, I have to write:
> Example[[1]][[1]]...i times...[[1]][[2]]  (first component)
> Example[[1]]...(i-1)times[[1]][[2]] (second component)
> ...
>
> Can I make it in some other way?
>
>
> Thanks,
>
> Arnau.
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>




More information about the R-help mailing list