我有两个列表,每列有18个数据帧,它们有两列,一列包含ids和其他数据。我的目标是通过id列完全加入这两个列表(第一个list1
与第一个list2
等等)的数据帧,使得生成的18个数据帧(再次存储在列表中)每个都有3列(一个id列,两个数据列)。如何连接两个数据帧的列表,获取第三个链接的数据帧列表?
Plesae注意,在list1
数据帧不一定具有相同的长度为那些在list2
,并在list1
的数据帧的数据列不同于一个在list2
命名。
这里是一个缩小例如:
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)