[R] About list to list

Patrick Burns pburns at pburns.seanet.com
Tue Apr 11 16:49:45 CEST 2006


If I understand what you want correctly:

 > foo1 <- list(c(10,20,30), c(11,21,31))
 > foo2 <- list(c(100,200,300), c(110,210,310))
 > foo3 <- list(c(1000,2000,3000), c(1100,2100,3100))
 > fool <- list(foo1, foo2, foo3)
 > lapply(fool, function(x) do.call('rbind', x))
[[1]]
     [,1] [,2] [,3]
[1,]   10   20   30
[2,]   11   21   31

[[2]]
     [,1] [,2] [,3]
[1,]  100  200  300
[2,]  110  210  310

[[3]]
     [,1] [,2] [,3]
[1,] 1000 2000 3000
[2,] 1100 2100 3100

Patrick Burns
patrick at burns-stat.com
+44 (0)20 8525 0696
http://www.burns-stat.com
(home of S Poetry and "A Guide for the Unwilling S User")

Muhammad Subianto wrote:

>Dear all,
>I have a result my experiment like this below (here my toy example):
>
>foo1 <- list()
>foo1[[1]] <- c(10, 20, 30)
>foo1[[2]] <- c(11, 21, 31)
>
>foo2 <- list()
>foo2[[1]] <- c(100, 200, 300)
>foo2[[2]] <- c(110, 210, 310)
>
>foo3 <- list()
>foo3[[1]] <- c(1000, 2000, 3000)
>foo3[[2]] <- c(1100, 2100, 3100)
>
>list(foo1,foo2,foo3)
>
>The result:
>  
>
>>list(foo1,foo2,foo3)
>>    
>>
>[[1]]
>[[1]][[1]]
>[1] 10 20 30
>
>[[1]][[2]]
>[1] 11 21 31
>
>[[2]]
>[[2]][[1]]
>[1] 100 200 300
>
>[[2]][[2]]
>[1] 110 210 310
>
>[[3]]
>[[3]][[1]]
>[1] 1000 2000 3000
>
>[[3]][[2]]
>[1] 1100 2100 3100
>
>  
>
>I want to convert like this below (as list).
>
>[[1]]
>[1] 10 20 30
>[2] 11 21 31
>
>[[2]]
>[1] 100 200 300
>[2] 110 210 310
>
>[[3]]
>[1] 1000 2000 3000
>[2] 1100 2100 3100
>
>I saw on the R-help archives page similar like this but I can't find a
>solution.
>http://tolstoy.newcastle.edu.au/R/help/05/05/4678.html
>Thanks very much for any suggestions.
>
>Sincerely, Muhammad Subianto
>
>______________________________________________
>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