Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201943

R match date in one table if between two date columns in second table over category

$
0
0

Using base R only, I'm trying to iterate and test if table1$"DATE" is >= table2$"START"& <= table2$"STOP" where table1$"EVENT" == table2$"EVENT". I initially thought to get unique categories from table1$"EVENT" and then subset via looping then outer-joining to table2 and after that using for-loop to iterate each table1 row against table2 rows to return the value but for loops are slow and my real data set has over 3 million rows and is grows daily. In Python I'd probably try something with pd.intervalrange or some similar approach.

This is the table of events I want to return a value to based on if DATE is between table2's START and STOP columns where EVENT matches in both table1 and table2.

table1

enter code here

table2 (lookup table)

enter image description here

desired outcome

enter image description here


Viewing all articles
Browse latest Browse all 201943

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>