0

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

Haim Katz
  • 455
  • 3
  • 13
  • First: please make this question *reproducible*. This includes sample code you've attempted, sample *unambiguous* data (e.g., `dput(head(x))` or `data.frame(x=...,y=...)`), and expected output. Refs: https://stackoverflow.com/questions/5963269, https://stackoverflow.com/help/mcve, and https://stackoverflow.com/tags/r/info. – r2evans Mar 18 '20 at 14:00
  • Second: did you know that Stack sites' netiquette typically has the best answer marked as "accepted" (checkmark, top-left of the specific answer). It not only provides a little perk to the answerer with some points, but also provides some closure for readers with similar questions. Though you can only accept one answer (if multiple provided), you have the option to up-vote as many as you think are helpful. Consider going to your [past questions](https://stackoverflow.com/users/4964214/haim-katz?tab=questions) (with answers) and [accept some](https://stackoverflow.com/help/someone-answers). – r2evans Mar 18 '20 at 14:03

0 Answers0