0

I have this problem that i want to fix. I want to create news columns in my data frame according to a condition that i take the Canal element where the date is the more recent ( the max ). My data is like follow:

[enter image description here]

and what i want is :

output DF:

[enter image description here]

I want to create the last two columns (WinnerInteraction & WinnerCanal) based on the max InteractionDate. So for each conversion ID (ConvID) it should look at the interaction Date and then select the max (the max hour if it's the same date) . Then it will extract the interaction and canal from that line.

  • 6
    Might want to look at guidance for asking R questions for future reference: https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example/28481250#28481250 It's easier for others to help if your data is reproducible. – Frank Apr 10 '18 at 16:40
  • Besides providing a reproducible example you should also clarify your criteria. What do you mean by max InteractionDate? For example if I look at ConvID 3116 all entries share the same date (21/03/2018) but differ in time. The largest (max) time value is 16:50 which matches the values "Click" and "PMP". But you would like to select "TV" and "Tv" that match 10:51. So it is hard to understand your criteria. You might be intersted in the `group_by()` function of the `dplyr`package. – FAMG Apr 10 '18 at 17:07
  • @FAMG You do, the max InteractionDate will take for the max time our if it's the same date and you're right, sorry. – iamchristophe Apr 10 '18 at 21:52

0 Answers0