I have data that looks like this:
d <- data.table(SEQ = c(1, 1, 2, 2,
1, 2, 2, 3,
1, 1, 2, 3,
3, 4, 5, 5),
TYPE = c("A", "A", "B", "B",
"C", "C", "C", "C",
"D", "D", "D", "D",
"D", "D", "D", "D"),
CLASS = c(1.1, 2.1, 3.3, 4.5,
1.3, 2.4, 3.4, 4.6,
1.4, 2.5, 3.6, 4.0,
1.4, 2.7, 3.2, 4.5))
That looks like this:
I want to filter this down into a new table, call it b
.
The logic for filtering would be for each unique(TYPE)
only keep the last row for each unique(SEQ)
. I know I can get this done with some for
loops but I would like to avoid that.
The expected output for the sample data would be:
If anyone has any suggestions of efficient ways to filter, I am all ears. Thanks!