[R] how to get such a subset of a matrix?
Dimitris Rizopoulos
dimitris.rizopoulos at med.kuleuven.ac.be
Fri May 6 15:36:51 CEST 2005
one way to do it is:
mat <- matrix(rnorm(20*20), 20, 20)
mat[sample(400, 40)] <- NA
#####
mat
mat[rowSums(is.na(mat)) <= 2, ]
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/336899
Fax: +32/16/337015
Web: http://www.med.kuleuven.ac.be/biostat/
http://www.student.kuleuven.ac.be/~m0390867/dimitris.htm
----- Original Message -----
From: "Xiao Shi" <bioconductor.cn at gmail.com>
To: <r-help at stat.math.ethz.ch>
Sent: Friday, May 06, 2005 3:21 PM
Subject: [R] how to get such a subset of a matrix?
> Hi everybody,
> Maybe this question is quite simple but i just don't know how to
> make it.
> I have a matrix a somewhat like this one but bigger:
>> a
> f g h i j k
> a NA NA 11 16 21 26
> b NA NA 12 17 22 27
> c NA 8 13 18 23 28
> d NA 9 14 19 24 29
> e NA 10 15 20 25 30
> And i want to get the rows which at most have 2 Na.
> Thanks in advance.
> Shi Jiantao
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> 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