Gaa*_*aaa 0 r list nested-lists dataframe
我正在尝试将嵌套列表转换为数据框。我想从 3 维获取数据框。到目前为止我用计数器指定i将嵌套列表的哪个维度作为数据帧,但我想从维度 1、2 和 3 获取数据帧。
感谢您的帮助
l <- list(list(list(x = 1, y = 2, 3, 4),
list(x = 3, y = 4, 5, 6)),
list(list(x = 1, y = 2, 3, 4)),
list(list(x = 2, y = 3, 4, 5)))
i = 3
a <- data.frame(do.call(rbind, l[[i]]))
Run Code Online (Sandbox Code Playgroud)
像这样?
library(tibble)
library(tidyr)
enframe(l) %>%
unnest(value) %>%
unnest_wider(value)
Run Code Online (Sandbox Code Playgroud)
name x y ...3 ...4
<int> <dbl> <dbl> <dbl> <dbl>
1 1 1 2 3 4
2 1 3 4 5 6
3 2 1 2 3 4
4 3 2 3 4 5
Run Code Online (Sandbox Code Playgroud)