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
You can try na. omit() or na. exclude() too. It might help you.
To remove all rows having NA, we can use na. omit function. For Example, if we have a data frame called df that contains some NA values then we can remove all rows that contains at least one NA by using the command na. omit(df).
Declare a boolean vector that has TRUE at all the positions you want to retain and FALSE at those you want to delete. Suppose that vector is y. Then, x[y] will give you the requires output.
To remove observations with missing values in at least one column, you can use the na. omit() function. The na. omit() function in the R language inspects all columns from a data frame and drops rows that have NA's in one or more columns.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With