I am trying to write some code to only keep rows in my data frame that:
have the same ID but different Dates.
Below is my current and desired application date.
I am trying to write some code to only keep rows in my data frame that:
have the same ID but different Dates.
Below is my current and desired application date.
We can group by 'ID', filter
the IDs with number of distinct 'Date' are greater than 1
library(dplyr)
df1 %>%
group_by(ID) %>%
filter(n_distinct(Date, na.rm = TRUE) > 1) %>%
ungroup
Or in base R
subset(df1, ID %in% names(which(table(unique(df1[c('ID', 'Date')])$ID) > 1)))