Skip to content

Subsets without NA

3 messages · Agustin Lobo, Kjetil Halvorsen, Brian Ripley

#
This function removes all rows
with at least one NA:
(x is a mtrix)
function(x)
{
        resultado <- x[!is.na(abs(x) %*% rep(1, ncol(x))),  ]
        resultado
}

i.e.:
[,1] [,2] [,3]
[1,]    1    5    9
[2,]    2    6   10
[3,]    3    7   11
[4,]    4    8   12
[,1] [,2] [,3]
[1,]   NA    5    9
[2,]    2   NA   NA
[3,]    3    7   11
[4,]    4    8   12
[,1] [,2] [,3]
[1,]    3    7   11
[2,]    4    8   12
Hope it helps

Agus

Dr. Agustin Lobo
Instituto de Ciencias de la Tierra (CSIC)
Lluis Sole Sabaris s/n
08028 Barcelona SPAIN
tel 34 93409 5410
fax 34 93411 0012
alobo at ija.csic.es
On Tue, 8 Jan 2002, Grum, Mikkel wrote:

            
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
#
But you can use the inbuilt function complete.cases().

Kjetil Halvorsen


This function removes all rows
.-.-.-
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._.
_._
.-.-.-
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._.
_._


-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
#
On Tue, 8 Jan 2002, Kjetilh Halvorsen wrote:

            
or the inbuilt function na.omit which does the whole job, as Uwe Ligges
pointed out some time ago in this thread.
[,1] [,2] [,3]
[1,]    3    7   11
[2,]    4    8   12
attr(,"na.action")
[1] 1 2
attr(,"na.action")attr(,"class")
[1] "omit"