[R] Subsetting dataframe with missing values

Rui Barradas ruipbarradas at sapo.pt
Thu Apr 26 23:38:07 CEST 2012


Hello,

Try ?is.na.
In the example below I've changed your first row name from NA to NA.0

x <- read.table(text="
       ID Category Sex  Beak   Head
NA.0     <NA>     <NA>  NA    NA     NA
NA.1   <NA>     <NA>  NA    NA     NA
NA.2   <NA>     <NA>  NA    NA     NA
NA.3   <NA>     <NA>  NA    NA     NA          
NA.4   <NA>     <NA>  NA    NA     NA          
NA.5   <NA>     <NA>  NA    NA     NA          
NA.6   <NA>     <NA>  NA    NA     NA          
9     LAA10    Adult   1 57.40 121.95      
10    LAA11    Adult   1 56.40 113.00      
11    LAA12    Adult   1 52.00 111.85      
13    LAA14    Adult   1 56.55 124.85      
15    LAA16    Adult   1 57.15 120.10      
NA.7   <NA>     <NA>  NA    NA     NA          
NA.8   <NA>     <NA>  NA    NA     NA          
21    LAA22    Adult   1 56.85 117.35      
22    LAA23    Adult   1 54.80 117.45      
27    LAA28    Adult   1 59.00 116.75      
28    LAA29    Adult   1 55.95 124.25      
NA.9   <NA>     <NA>  NA    NA     NA          
30    LAA31    Adult   1 57.70 112.80      
NA.10  <NA>     <NA>  NA    NA     NA          
NA.11  <NA>     <NA>  NA    NA     NA          
NA.12  <NA>     <NA>  NA    NA     NA          
NA.13  <NA>     <NA>  NA    NA     NA          
NA.14  <NA>     <NA>  NA    NA     NA          
NA.15  <NA>     <NA>  NA    NA     NA          
NA.16  <NA>     <NA>  NA    NA     NA          
NA.17  <NA>     <NA>  NA    NA     NA          
NA.18  <NA>     <NA>  NA    NA     NA          
NA.19  <NA>     <NA>  NA    NA     NA 
", header=TRUE)
rownames(x) <- seq.int(nrow(x))
head(x)

i1 <- is.na(x$Category)
i2 <- is.na(x$Sex)

x[!i1 & !i2, ]

Hope this helps,

Rui Barradas


--
View this message in context: http://r.789695.n4.nabble.com/Subsetting-dataframe-with-missing-values-tp4590819p4591052.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list