Suppose I have the following dataset:
df1 <- data_frame(date = c("2021-01-01", "2021-01-03", "2021-01-05", "2021-01-01", "2021-01-02", "2021-01-03", "2021-01-02", "2021-01-04", "2021-01-06"),
group = c("A", "A", "A", "B", "B", "B", "C", "C", "C"),
type = c("blue", "blue", "blue", "green", "green", "red", "yellow", "blue", "purple"))
I want to identify, for each group and type, if there's a future date for the same combination of group and type. This would yield me the following df:
df1 <- data_frame(date = c("2021-01-01", "2021-01-03", "2021-01-05", "2021-01-01", "2021-01-02", "2021-01-03", "2021-01-02", "2021-01-04", "2021-01-06"),
group = c("A", "A", "A", "B", "B", "B", "C", "C", "C"),
type = c("blue", "blue", "blue", "green", "green", "red", "yellow", "blue", "purple"),
future_date = c("2021-01-03", "2021-01-05", NA, "2021-01-02", NA, NA, NA, NA, NA))