[R] remove NA in df results in NA, NA.1 ... rows

Gerrit Eichner Gerrit.Eichner at math.uni-giessen.de
Thu Dec 13 09:48:30 CET 2012


Hi Raphael,

see below.

> I have the following data frame (df):
> ...
> > df2
>
>     X.PAD2 Y.PAD2
> 73 574618.3 179650
> 74 574719.0 179688
> 75 574719.0 179688
> 76 574723.5 179678
> 77 574724.9 179673
> 78 574747.1 179598
> 79 574641.8 179570
> 80 574639.6 179573
> 81 574618.3 179650
> 82       NA     NA
> 83       NA     NA
> ...
> 44       NA     NA
> 45       NA     NA
> 46       NA     NA
>
> followed by removing the NA's using
>
> > df2 <- df2[!is.na(df2),]
>
> ...

is.na( df2) produces a logical matrix (!), and you are then indexing the 
rows of your data frame with a matrix which is "converted" into a vector 
of its elements producing far too many logical indices for your task (so 
to say).

I assume you should be using

> na.omit( df2)

instead.

  Hth  --  Gerrit

---------------------------------------------------------------------
Dr. Gerrit Eichner                   Mathematical Institute, Room 212
gerrit.eichner at math.uni-giessen.de   Justus-Liebig-University Giessen
Tel: +49-(0)641-99-32104          Arndtstr. 2, 35392 Giessen, Germany
Fax: +49-(0)641-99-32109        http://www.uni-giessen.de/cms/eichner




More information about the R-help mailing list