Am 19.08.2020 um 19:15 schrieb Artur Tarassow:
Am 19.08.20 um 18:32 schrieb Alecos Papadopoulos:
> originally. But what would happen if in some row I would have some
> numbers and some "nan"? Will the meanr() return then a "nan"
result?
Yes I gues so.
Here is a hack from Jack. He posted it some years ago:
<hansl>
function matrix my_meanc(const matrix X)
matrix B = ok(X)
return sumc(B ? X : 0) ./ sumc(B)
end function
matrix A = {NA, 1; 2, 2; 1, 3}
mA = my_meanc(A)
mA
</hansl>
Thanks Artur, that's a nice reminder.
If the missings are not "dispersed" individually but it is always an
entire row which doesn't have valid numbers I guess you could also do
something like the following:
<hansl>
# small example matrix
matrix B = I(2)
B[2, ] = NA
print B
eval meanc( selifr(B, minr(ok(B)) ) )
</hansl>
But not very pretty to read I guess.
(BTW, it seems missing() doesn't work on a matrix, in contrast to ok() -
is that an oversight?)
cheers
sven