Skip to content

sum(NA,na.rm=T)

1 message · Jonathan Baron

#
This is zero!

That causes serious problems when I'm using sum() or mean() to
get the sum or mean of the non-missing data for each of several
subjects, some of whom have all data missing (on some variable),
and thus get a mean of 0.  E.g., with
apply(matrix1,1,sum,na.rm=T)
some rows have all NA's, so the result I want is NA, but I get 0.

Is there an ELEGANT workaround that gives NA instead of 0?