On Thu, 15 Oct 2015, Artur T. wrote:
Dear all,
I would like to compute the mean of a vector which involves NAs, implying
that the NAs should simply be neglected/not counted. But this is not the
way gretl handles matrices:
<gretl>
matrix A = {NA, 1; 2, 2; 1, 3}
mA = meanc(A)
mA
</gretl>
yields
<output>
mA (1 x 2)
nan 2
</output>
Is this intended? For instance, R, it seems, fully neglects the NAs and
computes the mean.
Hope this helps.
<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>
-------------------------------------------------------
Riccardo (Jack) Lucchetti
Dipartimento di Scienze Economiche e Sociali (DiSES)
Università Politecnica delle Marche
(formerly known as Università di Ancona)
r.lucchetti(a)univpm.it
http://www2.econ.univpm.it/servizi/hpp/lucchetti
-------------------------------------------------------