[R] Skip NA and alter length

Dimitris Rizopoulos dimitris.rizopoulos at med.kuleuven.be
Wed Nov 29 17:22:24 CET 2006


try this:

mat <- matrix(1:25, 5, 5)
mat[sample(25, 3)] <- NA
#########
mat
colSums(!is.na(mat))


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/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
     http://www.student.kuleuven.be/~m0390867/dimitris.htm


----- Original Message ----- 
From: "Syed Abid Hussaini" <ohitsabid at yahoo.com>
To: <r-help at stat.math.ethz.ch>
Sent: Wednesday, November 29, 2006 4:58 PM
Subject: [R] Skip NA and alter length


> Hi,
>
> This is my first post.
>
> Problem:
>
> I have a matrix 5 by 5 and it has 3 NAs in them. Now, when i use 
> length () for a particular column
> which has NA it returns 5. I know this is true, but how do i change 
> my matrix such that the length
> becomes 5 minus the number of NAs i have. I know NA has a length of 
> 1, but then how do i convert
> the NA into NULL whose length is 0.
>
> Thanks in advance.
>
> abid
>
> ______________________________________________
> 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
> and provide commented, minimal, self-contained, reproducible code.
> 


Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm



More information about the R-help mailing list