# Re: [R] Arrange a multi-level list to a one-level list

From: Phil Spector <spector_at_stat.berkeley.edu>
Date: Fri, 27 May 2011 15:29:49 -0700 (PDT)

Lisa -

Are you looking for this?

```+ matrix(sample(c(2,3), 4, replace = T), 2)),
+ list(matrix(sample(c(0,1), 6, replace = T), 2), matrix(sample(c(2,3), 6,
+ replace = T), 2)))
```

> unlist(x,recursive=FALSE)

[]

[,1] [,2]
[1,] 0 0
[2,] 1 0

[]

[,1] [,2]
[1,] 3 2
[2,] 3 2

[]

[,1] [,2] [,3]
[1,] 1 0 1
[2,] 0 1 0

[]

[,1] [,2] [,3]
[1,] 2 2 2
[2,] 2 2 3

• Phil Spector Statistical Computing Facility Department of Statistics UC Berkeley spector_at_stat.berkeley.edu

On Fri, 27 May 2011, Lisa wrote:

> Dear all,
>
> I just want to arrange a multi-level list to a one-level list. For example:
>
> x <- list(list(matrix(sample(c(0,1), 4, replace = T), 2),
> matrix(sample(c(2,3), 4, replace = T), 2)),
> list(matrix(sample(c(0,1), 6, replace = T), 2), matrix(sample(c(2,3), 6,
> replace = T), 2)))
>
>> x
> []
> [][]
> [,1] [,2]
> [1,] 1 1
> [2,] 0 0
>
> [][]
> [,1] [,2]
> [1,] 3 2
> [2,] 3 3
>
>
> []
> [][]
> [,1] [,2] [,3]
> [1,] 1 0 0
> [2,] 0 1 0
>
> [][]
> [,1] [,2] [,3]
> [1,] 2 3 3
> [2,] 3 3 3
>
> If I do this work one time, I will arrange it like this:
>
> c(x[], x[]) # Only consider the first level of the list.
>
> []
> [,1] [,2]
> [1,] 1 1
> [2,] 0 0
>
> []
> [,1] [,2]
> [1,] 3 2
> [2,] 3 3
>
> []
> [,1] [,2] [,3]
> [1,] 1 0 0
> [2,] 0 1 0
>
> []
> [,1] [,2] [,3]
> [1,] 2 3 3
> [2,] 3 3 3
>
> But when I repeat this work many times and the levels will change each time
> in a loop, how can I pass the arguments to c()? For example, in the first
> iteration, the first level of a list is 3, in the second iteration, the
> first level of a list is 5? ….
>
> Any help would be greatly appreciated.
>
> Lisa
>
>
> --
> View this message in context: http://r.789695.n4.nabble.com/Arrange-a-multi-level-list-to-a-one-level-list-tp3556500p3556500.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help_at_r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help