I have a data frame with 3 columns: custId, saleDate, DelivDateTime.
> head(events22) custId saleDate DelivDate 1 280356593 2012-11-1
This should be pretty fast but data.table is likely faster:
data.table
do.call(rbind, lapply(split(events22, events22$custId), function(x){ x[which.max(x$saleDate), ] }) )