Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201919

Filter and group by with data.table

$
0
0

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.


Viewing all articles
Browse latest Browse all 201919

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>