[Rd] Inconsistency between rowMeans documentation and reality?

From: Gavin Simpson <gavin.simpson_at_ucl.ac.uk>
Date: Tue, 05 Apr 2011 12:33:06 +0100

Dear List,

I'm not even sure this is an issue or not, but ?rowMeans has:


     A numeric or complex array of suitable size, or a vector if the
     result is one-dimensional.  The ‘dimnames’ (or ‘names’ for a
     vector result) are taken from the original array.

     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’.

However the output of mean() and rowMeans() is not exactly the same when all supplied values are missing.

> mean(NA, na.rm = TRUE)

[1] NaN
> mean(rep(NA, 5), na.rm = TRUE)

[1] NaN
> rowMeans(matrix(rep(NA, 5), ncol = 5), na.rm = TRUE)
[1] NA

So in one sense, the outputs are not consistent:

> is.nan(mean(rep(NA, 5), na.rm = TRUE))
[1] TRUE
> is.nan(rowMeans(matrix(rep(NA, 5), ncol = 5), na.rm = TRUE))
[1] FALSE but in another they are:

> is.na(mean(rep(NA, 5), na.rm = TRUE))
[1] TRUE
> is.na(rowMeans(matrix(rep(NA, 5), ncol = 5), na.rm = TRUE))
[1] TRUE I'm not familiar enough with the details to know if this even matters, but wonder if something in the documentation needs a change or tweak to clarify what is returned. As I say, in one sense the outputs are not consistent.

> sessionInfo()

R version 2.13.0 beta (2011-04-04 r55298) Platform: x86_64-unknown-linux-gnu (64-bit)


 [1] LC_CTYPE=en_GB.utf8       LC_NUMERIC=C             
 [3] LC_TIME=en_GB.utf8        LC_COLLATE=en_GB.utf8    
 [5] LC_MONETARY=C             LC_MESSAGES=en_GB.utf8   
 [7] LC_PAPER=en_GB.utf8       LC_NAME=C                
 [9] LC_ADDRESS=C              LC_TELEPHONE=C           

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods  
[7] base     

loaded via a namespace (and not attached): [1] tools_2.13.0



 Dr. Gavin Simpson             [t] +44 (0)20 7679 0522
 ECRC, UCL Geography,          [f] +44 (0)20 7679 0565
 Pearson Building,             [e] gavin.simpsonATNOSPAMucl.ac.uk
 Gower Street, London          [w] http://www.ucl.ac.uk/~ucfagls/
 UK. WC1E 6BT.                 [w] http://www.freshwaters.org.uk

R-devel_at_r-project.org mailing list
Received on Tue 05 Apr 2011 - 11:31:46 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 11 Apr 2011 - 15:20:44 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.

list of date sections of archive