元素的rbind rbind rbind列表r
我有一个3个列表的列表,每个列表具有相等数量的数据范围,即32,我希望在列表元素上rbind
它们。为了举一个更简单的示例,假设您有一个带有2个列表的列表,每个列表都有2个数据范围,例如:
[[1]]
[[1]][[1]]
x y
1 a 11
2 b 12
3 c 13
[[1]][[2]]
x y
1 a 14
2 b 15
3 c 16
[[2]]
[[2]][[1]]
x y
1 a 17
2 b 18
3 c 19
[[2]][[2]]
x y
1 a 21
2 b 22
3 c 23
给出:
A <- data.frame(c("a","b","c"), c(11,12,13))
colnames(A)<-c("x","y")
B <- data.frame(c("a","b","c"), c(14,15,16))
colnames(B)<-c("x","y")
C <- data.frame(c("a","b","c"), c(17,18,19))
colnames(C)<-c("x","y")
D <- data.frame(c("a","b","c"), c(21,21,23))
colnames(D)<-c("x","y")
L1 <- list(A,B)
L2 <- list(C,D)
L <- list(L1,L2)
我如何rbind
在2个列表元素上的数据范围,以便最终输出
是:
[[1]]
x y
1 a 11
2 b 12
3 c 13
4 a 17
5 b 18
6 c 19
[[2]]
x y
1 a 14
2 b 15
3 c 16
4 a 21
5 b 21
6 c 23
在此示例中,我可以output&lt; - list(rbind(a,c),rbind(b,d))
,
但我想做它适用于更大的数据范围列表
I have a list of 3 lists, each with an equal number of dataframes, 32, to be precise, and I wish to rbind
them across the lists element-wise. To give a simpler example, suppose you have one list with 2 lists, each with 2 dataframes, like this:
[[1]]
[[1]][[1]]
x y
1 a 11
2 b 12
3 c 13
[[1]][[2]]
x y
1 a 14
2 b 15
3 c 16
[[2]]
[[2]][[1]]
x y
1 a 17
2 b 18
3 c 19
[[2]][[2]]
x y
1 a 21
2 b 22
3 c 23
given by:
A <- data.frame(c("a","b","c"), c(11,12,13))
colnames(A)<-c("x","y")
B <- data.frame(c("a","b","c"), c(14,15,16))
colnames(B)<-c("x","y")
C <- data.frame(c("a","b","c"), c(17,18,19))
colnames(C)<-c("x","y")
D <- data.frame(c("a","b","c"), c(21,21,23))
colnames(D)<-c("x","y")
L1 <- list(A,B)
L2 <- list(C,D)
L <- list(L1,L2)
How can I rbind
the dataframes across the 2 lists element-wise, such that the final output
is:
[[1]]
x y
1 a 11
2 b 12
3 c 13
4 a 17
5 b 18
6 c 19
[[2]]
x y
1 a 14
2 b 15
3 c 16
4 a 21
5 b 21
6 c 23
In this example, I could just output <- list(rbind(A,C),rbind(B,D))
But I want to do it for a much larger list of lists of dataframes
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
怎么样:
由
How about this:
Created on 2022-05-26 by the reprex package (v2.0.1)
一个人可以从
purrr
中使用transpose
:One could just use
transpose
frompurrr
:您可以使用
map2
这样:输出:
You can use
map2
like this:Output:
基础r:
Base R: