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.
Hello, I don't know if it is the most efficient way to do but my solution is: x <- vector("list", 10) #creates a list with a length = 10 then in my loop (where i is iterated) : x[[i]] <- my.vector I hope this could help you François Michonneau 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. [[alternative HTML version deleted]]
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 >