COUNTN Function

COUNTN (x <, method> ) ;

The COUNTN function counts the number of nonmissing values in a matrix. The arguments are as follows:

x

specifies an $n\times p$ numerical or character matrix. The COUNTN function counts the number of nonmissing values in this matrix.

method

specifies the method used to count the nonmissing values. This argument is optional. The following are valid values:

all

specifies that all nonmissing values are counted. This is the default value. The function returns a $1\times 1$ matrix.

row

specifies that the function return an $n\times 1$ matrix whose $i$th element is the number of nonmissing values in the $i$th row of x.

col

specifies that the function return a $1\times p$ matrix whose $j$th element is the number of nonmissing values in the $j$th row of x.

The method argument is not case-sensitive. The first three characters are used to determine the value.

For example, the following statements count nonmissing values for a matrix x:

x = {1 2 3,
     . 0 2, 
     1 . .,
     1 0 . };
totalN = countn(x);
rowN = countn(x, "ROW");
colN = countn(x, "COL");
print totalN, rowN, colN;

Figure 23.72: Counts of Nonmissing Values

totalN
8

rowN
3
2
1
2

colN
3 3 2