On Fri, 15 Oct 2004, Luis Rideau Cruz wrote:

> R-help
>
> I have a martix with missing values( in which I want the sample size by
> column)
> When I :
>
> apply(matrix,2,length)
>
> 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?

You could omit the missing values before:
  apply(matrix, 2, function(y) length(na.omit(y)))

hth,
Z

> Thank you
>
> ______________________________________________
> [EMAIL PROTECTED] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>

______________________________________________
[EMAIL PROTECTED] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

Reply via email to