我有两个数据框:
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
我想将这两个数据框组合成单个列表,如下所示:
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)]
我试图重新绑定两个数据帧,然后按相同的列拆分,但它导致多个列表而不是一个列表。 感谢您的任何建议。
答案 0 :(得分:1)
我们可以尝试
Map(function(x,y) do.call(paste, c(data.frame(x,y), sep=";")), DF1, DF2)
或
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]]