[R] NA, deleting rows

Thomas Lumley tlumley at u.washington.edu
Thu Dec 18 17:04:54 CET 2003


On Thu, 18 Dec 2003, juli g. pausas wrote:

> Dear colleges,
> I do not understand the following behaviour:
>
> > aa <- data.frame(a1= 1:10, a2= c(rep(NA, 5), 1:5) )

> > aa[!aa$a2==1, ]  # removing rows with a2==1
>      a1 a2
> NA   NA NA
> NA.1 NA NA
> NA.2 NA NA
> NA.3 NA NA
> NA.4 NA NA
> 7     7  2
> 8     8  3
> 9     9  4
> 10   10  5
>
> I didn't expect a1 to be affected.

You should think of NA as being pronounced "Don't Know".  That is you are
asking for all rows where a2==1 to be removed and you don't know whether
to remove the first five rows. The result is that you don't know what the
result is in the first five rows.

There is a good case for making this give an error or warning.

	-thomas




More information about the R-help mailing list