将两个带有数据框的列表合并为一个带有合并数据框的列表

Merge two lists with dataframes into one list with merged dataframes

我有两个数据框列表:listA 和 listB。如何获取合并数据框列表(listC)?

dfA1 <- data.frame(x1 = c("a", "b"), y1 = c(1, 2), row.names = c("1", "2"))
dfA2 <- data.frame(x1 = c("c", "d"), y1 = c(3, 4), row.names = c("1", "3"))
dfB1 <- data.frame(x2 = c("c", "d"), y2 = c(3, 4), row.names = c("1", "2"))
dfB2 <- data.frame(x2 = c("e", "f"), y2 = c(5, 6), row.names = c("2", "3"))

listA <- list(dfA1, dfA2) # first input list
listB <- list(dfB1, dfB2) # second input list

m1 <- merge(dfA1, dfB1, by = 0, all = T)
m2 <- merge(dfA2, dfB2, by = 0, all = T)
listC <- list(m1, m2) # desired output list

找到以下解决方案:

listC <- mapply(function(x, y) merge(x, y, by = 0, all = T), x = listA, y = listB, SIMPLIFY = F)