[R] Finding Highest value in groups

Giorgio Garziano giorgio.garziano at ericsson.com
Fri Apr 22 20:47:41 CEST 2016


Since the aggregate S3 method for class formula already has got na.action = na.omit,

## S3 method for class 'formula'
aggregate(formula, data, FUN, ...,
          subset, na.action = na.omit)


I think that to deal with NA's, it is enough:

   aggregate(Value~ID, dta, max)

Moreover, passing na.rm = FALSE/TRUE is "don't care":

aggregate(Value~ID, dta, max, na.rm=FALSE) result is:

  ID Value
1  1  0.69
2  2  0.99
3  3  1.00
4  4  1.00
5  5  0.50

which is the same of na.rm=TRUE.

On the contrary, in the following cases:

aggregate(Value~ID, dta, max, na.action = na.pass)

  ID Value
1  1  0.69
2  2  0.99
3  3  1.00
4  4    NA
5  5  0.50

aggregate(Value~ID, dta, max, na.action = na.fail)

  Error in na.fail.default(list(Value = c(0.69, 0.31, 0.01, 0.99, 1, NA


the result is different.

--

Best,

GG





	[[alternative HTML version deleted]]



More information about the R-help mailing list