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]]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.