[英]Create a single list from two data frames
I have two data frames: 我有两个数据框:
DF1
e l u
1 0.5 1.5
2 1 3
3 2 4
DF2
e l u
0.1 0.01 0.15
0.2 0.1 0.3
0.3 0.2 0.4
I want to combine these two data frames into single list like so: 我想将这两个数据帧合并为一个列表,如下所示:
L
[[1]]
$e: [(1,0.1);(2,0.2);(3,0.3)]
$l: [(0.5,0.01);(1,0.1);(2,0.2)]
$u: [(1.5,0.015);(3,0.3);(4,0.4)]
I have tried to rbind two data frames and then split by same column, but it results in multiple lists not a single one. 我尝试过绑定两个数据帧,然后按同一列拆分,但是它导致多个列表而不是单个列表。 Thank you for any suggestions.
感谢您的任何建议。
We can try 我们可以试试
Map(function(x,y) do.call(paste, c(data.frame(x,y), sep=";")), DF1, DF2)
or 要么
library(jsonlite)
Map(function(x,y) toJSON(cbind(x,y)), DF1, DF2)
#$e
#[[1,0.1],[2,0.2],[3,0.3]]
#$l
#[[0.5,0.01],[1,0.1],[2,0.2]]
#$u
#[[1.5,0.15],[3,0.3],[4,0.4]]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.