Re: [R] Subsets without NA <A68A7C0BB344D511AA38005004AA9E18BA7E93@icrafnttrain.icraf.cgiar.org>

About this list Date view Thread view Subject view Author view Attachment view

From: Agustin Lobo (alobo@ija.csic.es)
Date: Wed 09 Jan 2002 - 01:11:16 EST


Message-id: <Pine.OSF.3.96.1020108150837.31232L-100000@ija.csic.es>

This function removes all rows
with at least one NA:
(x is a mtrix)

> no.na.mat
function(x)
{
        resultado <- x[!is.na(abs(x) %*% rep(1, ncol(x))), ]
        resultado
}

i.e.:

> mat <- matrix(1:12,ncol=3)
> mat
     [,1] [,2] [,3]
[1,] 1 5 9
[2,] 2 6 10
[3,] 3 7 11
[4,] 4 8 12
> mat [1,1] <- NA
> mat [2,c(2,3)] <- NA
> mat
     [,1] [,2] [,3]
[1,] NA 5 9
[2,] 2 NA NA
[3,] 3 7 11
[4,] 4 8 12
> no.na.mat(mat)
     [,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@ija.csic.es

On Tue, 8 Jan 2002, Grum, Mikkel wrote:

> Is there a way of removing all rows with missing values from a data frame?
> I usually use
> subset(x, var1!="NA")
> and repeat for each variable. It would be nice to be able to do it in one
> fell swoop. Also, surprisingly, it doesn't always work. Sometimes I'm left
> with an empty set even though not all rows have missing values for the
> variable.
>
> Cheers,
> mikkel
>
>
>
>
>
> Mikkel Grum, PhD
> Genetic Diversity Scientist
> International Plant Genetic Resources Institute (IPGRI)
> Sub-Saharan Africa Group
> ***
> c/o ICRAF
> PO Box 30677 Nairobi, Kenya
> Tel: 254 2 524505 / 524500
> Fax: 254 2 524501 / 524001
> m.grum@cgiar.org
> ipgri-kenya@cgiar.org
> www.ipgri.cgiar.org
>
> -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
> 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@stat.math.ethz.ch
> _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
>

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._


About this list Date view Thread view Subject view Author view Attachment view

This archive was generated by hypermail 2.1.3 : Thu 17 Jan 2002 - 11:10:11 EST