I have two large datasets, df1 and df2. The first dataset, df1, contains the columns \'ID\' and \'actual.data\'.
df1 <- data.frame(ID=c(1,1,1,2,3,4,4), a
Just another hopefully correct answer using the fuzzyjoin
package.
library(data.table)
library(fuzzyjoin)
dt1 <- data.table(df1)
dt2 <- data.table(df2)
fuzzy_left_join(dt1
, dt2,
by = c("ID" = "ID", "actual.date" = "before.date", "actual.date" = "after.date"),
match_fun = list(`==`, `>`, `<`))[,.(ID = ID.x
,actual.date
, match = ifelse(is.na(ID.y),0,1))]