Skip to content
Prev 63158 / 63424 Next

Do rowMeans and colMeans of complex vars need adjusting following r88444?

In SVN commit r88444, Martin made a change following Mikael's PR #18918. The
one-line synopsis is 'subassignment <complex>[i] <- NA should only touch the
real part' and you can see it all at [1].  Imaginary parts now get a zero.
I am wondering if that cause rowMeans and colMeans to be off?

A quick example under R-devel (as of today):
[,1] [,2] [,3]
[1,] 1+2i   NA 7+2i
[2,]   NA 5+2i   NA
[3,] 3+2i   NA 9+2i
[1] 4+1.333333i 5+0.666667i 6+1.333333i
But in R 4.5.1 we get the (here constant) imaginary part as constant just as
we do when we do this 'by hand' as rowSum() appears fine:
[1]  8+4i  5+2i 12+4i
[1] 2 1 2
[1] 4+2i 5+2i 6+2i
I could be off my rocker here as I don't use complex variables much and am a
little rustic but a rudimentary check suggests my reasoning applies: means of
real and imaginary parts (taken across rows or columns) should be the sum
divided by the number of non-NA elements.  Right now they aren't.

Cheers, Dirk

[1] https://github.com/r-devel/r-svn/commit/d65e9a52318921d1a105421b95e0fa6bebceeb55