I have two dataframes Event1 with the columns id, time, Event2_time, and Event2 with columns id, time. Both are ordered descending by time. I'm trying to set the Event1.Event2time for each row such that Event2_time = max(Event2.time< row.time) In c# it would look something like this:
var event1 = Event1.OrderByDescending(a => a.time);
var event2 = Event2.OrderByDescending(b => b.time);
foreach(Event1 e1 in event1)
{ e1.Event2_time = event2.Where(e => e.time < e1.time ).FirstOrDefault().time;
}
How can I do this in R (i'm using dplyr)? Haim