Skip to content
Prev 163985 / 398503 Next

How to force aggregate to exclude NA ?

How about writing a function to do the customisation for you?

na.rm <- function(f) {
  function(x, ...) f(x[!is.na(x)], ...)
}

aggregate(m[,-c(1:2)], by=list(m[,1]), na.rm(sum))
aggregate(m[,-c(1:2)], by=list(m[,1]), na.rm(length))

Hadley