Skip to content
Advertisement

R: “Fuzzy Match” and “Between” Statements

I am working with the R Programming Language. I have the following tables (note: all variables appear as “Factors”):

I am trying to “join” (e.g. inner join) this tables on the following conditions:

1) if table_1$id "fuzzy equal" table_2$id

AND

2) if table_1$date BETWEEN(table_2$date_2,table_2$date_3)

I tried to write the following code in R to do this:

Question: But I am not sure if the stringdist_inner_join function can accommodate this kind of “between” logic.

Can someone please show me how to do this? Are there any other methods to accomplish this in R?

Thanks!

Advertisement

Answer

How about this? We could do the stringdist_inner_join and filter afterwards if the dates are stored as dates. This should be plenty performant for most data, and if not you should probably use data.table instead of fuzzyjoin.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement