【发布时间】:2017-09-21 16:39:14
【问题描述】:
我有两个列表,每个列表包含 18 个数据框,其中包含两列,一列包含 id,另一列包含数据。我的目标是通过 id 列完全连接两个列表的数据帧(list1 的第一个与list2 的第一个等等),以便生成 18 个数据帧(再次存储在列表中)每个都有 3 列(一个 id 列,两个数据列)。
请注意list1 中的数据帧不一定与list2 中的数据帧具有相同的长度,并且list1 中数据帧的数据列与@987654326 中的数据列名称不同@。
这是一个缩小的例子:
list1 <- list(df1 = data.frame(id_col = c(1:3), data_1 = letters[1:3]),
df2 = data.frame(id_col = c(1:4), data_1 = letters[1:4]))
list2 <- list(df1 = data.frame(id_col = c(1:4), data_2 = LETTERS[1:4]),
df2 = data.frame(id_col = c(1:7), data_2 = LETTERS[1:7]))
我想解决方案是这样的:
mapply(function(x, y) {
# some function with e. g. dplyr::full_join
}, x = list1, y = list2)
【问题讨论】: