How can I add another variable as a grouping variable based on the date? Here is my data:
df <- tibble(id = c(rep(1, 8), rep(2, 3)),
col = structure(c(19031, 19031, 19031, 19031, 19072, 19072, 19072, 19072, 19031, 19031,
19031), class = "Date"),
grouping_var = c(rep(1, 4), rep(2,4), rep(1, 3) ) )
and the column grouping_variable is the expected outcome I want to have. So Basically, I want to assign a grouping based on the date. If an id has more than one date in the col then the first date gets assigned a 1 and the second a 2, and if an id has only one date the it only gets a 1. A dpylr solution would be particularly great here.
Thanks