0

I have a data frame which looks something like :

Year YearOfService NumberOfPeople
2000             24            43
2000             20            32
2000             34            20
2001             15            20
2001             18            5
2002             13            10
2002             20            5

and i want to transform it into:

Year YearOfService NumberOfPeople
2000  34               20
2001  18               5
2002  20               5

is there a way for me to only take the longest service time based on every year? Thank you for your suggestions !

Aiko
  • 1
  • Returning the complete row and not just the Group and the max is not straightforward and not answered directly in any of the given linked answers. So here is your solution: `t(sapply( unique(dat$Year), function(x) dat[dat$Year == x,][ which.max( dat[dat$Year == x,"YearOfService"] ),] ))` – Andre Wildberg Nov 16 '21 at 14:05

0 Answers0