在不了解每个数据帧的数据结构的情况下很难得出一个可靠的答案,但您可以利用 dplyr 的 left_join 函数来获得您想要的结果。这样的事情可能会帮助您获得所需的内容。
library(dplyr)
# Create test dataframes
A <- data.frame(datedone = c("1/1/2017", "2/2/2017","3/3/2017", "4/4/2017"),
organization = c("org1","org1","org2","org3"),
someotherdata = c("d1","d2","d3","d4"),
stringsAsFactors = FALSE)
B <- data.frame(datecreated = c("1/1/2017", "2/4/2017","3/3/2017", "4/4/2017"),
organization = c("org1","org1","org2","org3"),
someotherdata = c("d1","d2","d3","d4"),
stringsAsFactors = FALSE)
# Add column to each dataframe to act as an identifier
A$fromdf <- "A"
B$fromdf <- "B"
# Left join dataframe B onto dataframe A
AB <- A %>%
left_join(B, by = c("datedone" = "datecreated", "organization" = "organization")) %>%
# Create a new column to show if there was a match, based on whether a value is present in fromdf.y
mutate(ABmatch = ifelse(is.na(fromdf.y), FALSE, TRUE)) %>%
# Select whichever columns are needed from the dataframe
select(datedone, organization, someotherdata = someotherdata.x, ABmatch)