cbind two lists of data.frames to a new list [duplicate]

南楼画角 提交于 2020-08-19 04:36:37

问题


I have two lists of data.frames. Both lists have the same length and contain fitting data.frames in their according list elements. So the scenario looks like this

dfa = data.frame(a=1:3, b = letters[1:3])
dfb = data.frame(x=runif(3))
a = replicate(3, dfa, simplify = FALSE)
b = replicate(3, dfb, simplify = FALSE)

One obvious solution is:

lapply(seq_along(a), function(i) cbind(a[[i]], b[[i]]))

But I was wondering if their might be a better solution.


回答1:


You can use Map

Map(cbind, a, b)



回答2:


You can use mapply :

mapply(cbind, a, b, SIMPLIFY=F)


来源:https://stackoverflow.com/questions/28898261/cbind-two-lists-of-data-frames-to-a-new-list

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!