Skip to content
Prev 247076 / 398506 Next

aggregate.formula implicitly removes rows containing NA

The documentation for `aggregate` makes it sound like aggregate.formula should behave identically to aggregate.data.frame (apart from the way the parameters are passed).  But it looks like aggregate.formula is quietly removing rows where any of the "output" variables (those on the LHS of the formula) are NA.  This differs from how aggregate.data.frame works.  Is this expected behavior?

Here are a couple of examples:
+                 b=c(1,2,NA,3))
a   b
1 1 1.5
2 2  NA
a   b
1 1 1.5
2 2 3.0

It's removing whole rows even if just one of the columns is NA, i.e.:
+                 b=c(1,2,NA,3),
+                 c=c(NA,2,3,NA))
a b c
1 1 2 2

Daniel