[R] length with missing values
Dimitris Rizopoulos
dimitris.rizopoulos at med.kuleuven.ac.be
Fri Oct 15 13:23:48 CEST 2004
Hi Luis,
just use:
apply( mat, 2, function(x) length(x[!is.na(x)]) )
I hope it helps.
Best,
Dimitris
----
Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven
Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/16/396887
Fax: +32/16/337015
Web: http://www.med.kuleuven.ac.be/biostat/
http://www.student.kuleuven.ac.be/~m0390867/dimitris.htm
> ----- Original Message -----
> From: "Luis Rideau Cruz" <Luisr at frs.fo>
> To: <r-help at stat.math.ethz.ch>
> Sent: Friday, October 15, 2004 1:01 PM
> Subject: [R] length with missing values
>
>
>> 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?
>>
>> Thank you
>>
>> ______________________________________________
>> R-help at stat.math.ethz.ch mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide!
>> http://www.R-project.org/posting-guide.html
>>
>
>
More information about the R-help
mailing list