Let's say I have this data frame
time1 weight
<chr> <dbl>
1 2012-04-25 17:40:00 82
2 2012-04-25 18:40:00 81
I now have another data frame of the form:
time2 d1 d2 d3
<chr> <dbl> <dbl> <dbl>
1 2012-04-25 17:45:00 1 0 1
I now want to join these dataframes. However, I want to only use the original values in d1 d2 d3 if the time2 is greater than time1. Otherwise the values should be zero. That is I want:
time1 weight d1 d2 d3
<chr> <dbl> <dbl> <dbl> <dbl>
1 2012-04-25 17:40:00 82 0 0 0
2 2012-04-25 18:40:00 81 1 0 1
What's a sneaky way to do so?