Skip to content
Prev 157015 / 398506 Next

rowSums()

on 09/24/2008 09:06 AM Doran, Harold wrote:
The behavior you observe is documented in ?rowSums in the Value section:

If there are no values in a range to be summed over (after removing
missing values with na.rm = TRUE), that component of the output is set
to 0 (*Sums) or NA (*Means), consistent with sum and mean.


So:
[1] 0


As per the definition of the sum of an empty set being 0, which I got
burned on myself a while back.

You could feasibly use:

  Res <- rowSums(testDat, na.rm = TRUE)
  is.na(Res) <- rowSums(is.na(testDat)) == ncol(testDat)

HTH,

Marc Schwartz