I have the following data.table:
DT <- data.table(name = c('ana', 'ana', 'ana', 'ana', 'justin', 'justin', 'justin', 'justin'), age = c(12, 26, 24, 14, 28, 36, 17, 8))
I want to be able to group by name, order the ages, and remove all groups in which the second higher age is below 28. How can I do that with data.table?
The expected output should be:
data.table(name = c('justin', 'justin', 'justin', 'justin'), age = c(28, 36, 17, 8))
Since it will remove the 'ana' group, because the second higher age in that group is less than 28.