Thank you for the quick answers. Now I remember that there was a related discussion on the list a while ago. I understand the issues related to NAs in matrices, and actually it is not a big problem at all as there are ways to circumvent this easily.

> How are NAs (NaNs) getting into your matrix? Why do you think they ought to be ignored/skipped instead of propagating when doing calculations on the matrix?
I simply that I run a loop filling some columns of a zero matrix, but the length of the resulting column vectors vary. Hence, some entries remain zero, but before computing meanc(), I would like to discard the zero entries.

However, Jack's solution is just doing its job. Thank you, Jack!

Best wishes,
Artur

2015-10-15 2:02 GMT+02:00 Allin Cottrell <cottrell@wfu.edu>:
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.

Yes, it's intended. There's really no such thing as NA in a gretl matrix, the "closest translation" is NaN (not-a-number) and that's what gets written into the matrix if you give NA as an element. And NaN (a standard C-library/IEEE concept) turns everything it touches into another NaN: x + NaN = NaN, x * NaN = NaN, and so on.

How are NAs (NaNs) getting into your matrix? Why do you think they ought to be ignored/skipped instead of propagating when doing calculations on the matrix?

Allin Cottrell

_______________________________________________
Gretl-users mailing list
Gretl-users@lists.wfu.edu
http://lists.wfu.edu/mailman/listinfo/gretl-users