[R] length with missing values
sundar.dorai-raj at PDF.COM
Fri Oct 15 13:30:46 CEST 2004
Luis Rideau Cruz wrote:
> I have a martix with missing values( in which I want the sample size by
> When I :
> I get the length of the vector regardless of missing values.
> I can't pass an argument to length in apply.
> Alternatively I could
> ifelse ( is.na ( matrix [, "columns in matrix " ] ) , 0 , 1)
> Is there any easier way?
I think you almost have it:
colSums(ifelse(is.na(x), 0, 1))
will return the number of non-NA elements in each column of x.
Is that what you want?
More information about the R-help