繁体   English   中英

是否可以从另一个嵌套列表创建列表?

[英]Is it possible to create a list from another nested list?

我有一个处理了n个数据的列表,每个数据中有15个数组。 我必须为每种类型的数组创建一个列表,比如

list1 <- Dados_processados[[1]][[1]], Dados_processados[[2]][[1]], 
   Dados_processados[[3]][[1]]...Dados_processados[[n]][[1]]

这是数据的样子

在此输入图像描述

我试图用'while'做到这一点,但它出错了。

为了使示例更小,我将n设为3 ,每个列表为长度5而不是15

l <- list(
  as.list(1:5),
  as.list(11:15),
  as.list(21:25)
)
str(l)
#> List of 3
#>  $ :List of 5
#>   ..$ : int 1
#>   ..$ : int 2
#>   ..$ : int 3
#>   ..$ : int 4
#>   ..$ : int 5
#>  $ :List of 5
#>   ..$ : int 11
#>   ..$ : int 12
#>   ..$ : int 13
#>   ..$ : int 14
#>   ..$ : int 15
#>  $ :List of 5
#>   ..$ : int 21
#>   ..$ : int 22
#>   ..$ : int 23
#>   ..$ : int 24
#>   ..$ : int 25

purrr::transpose将按照您描述的方式将列表“从里到外”转换。

l2 <- purrr::transpose(l)
str(l2)
#> List of 5
#>  $ :List of 3
#>   ..$ : int 1
#>   ..$ : int 11
#>   ..$ : int 21
#>  $ :List of 3
#>   ..$ : int 2
#>   ..$ : int 12
#>   ..$ : int 22
#>  $ :List of 3
#>   ..$ : int 3
#>   ..$ : int 13
#>   ..$ : int 23
#>  $ :List of 3
#>   ..$ : int 4
#>   ..$ : int 14
#>   ..$ : int 24
#>  $ :List of 3
#>   ..$ : int 5
#>   ..$ : int 15
#>   ..$ : int 25

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM