Let's say we have a table like below. The same product run on the same machine more than one time, re-work or re-processed.
What we are interested in the last run.
Using base command aggregate
laste_entry_max <- aggregate(RUN_Number ~ ID, last_entry, max)
By doing a merge you can do the subset the table.
laste_entry_max_all_c <- merge(laste_entry_max, last_entry, by = c('ID', 'RUN_Number'), all.x = T)
You can also use dplyr package
library(dplyr)
laste_entry_max <- last_entry %>%
group_by(ID) %>%
slice(which.max(RUN_Number))