Possible Duplicate:
R script - removing NA values from a vector
I could I remove all the NAs from a Vector using R?
[1] 1 NA 3 NA 5
Thank you
Possible Duplicate:
R script - removing NA values from a vector
I could I remove all the NAs from a Vector using R?
[1] 1 NA 3 NA 5
Thank you
Use is.na
with vector indexing
x <- c(NA, 3, NA, 5)
x[!is.na(x)]
[1] 3 5
I also refer the honourable gentleman / lady to the excellent R introductory manuals, in particular Section 2.7 Index vectors; selecting and modifying subsets of a data set
In addition to @Andrie's answer, you can use na.omit
x <- c(NA, 3, NA, 5)
na.omit(x)
[1] 3 5
attr(,"na.action")
[1] 1 3
attr(,"class")
[1] "omit"