Last active
December 20, 2015 14:49
-
-
Save kongscn/6149396 to your computer and use it in GitHub Desktop.
Remove NA in R
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Reference: | |
# http://stackoverflow.com/questions/4862178/remove-rows-with-nas-in-data-frame | |
# example from ?na.omit, changed. | |
# use complete.cases to get a bool vector of cases without missing data. | |
DF <- data.frame(x = c(1, 2, 3), y = c(0, 10, NA), z = c(NA, 10, 6)) | |
DF[complete.cases(DF), ] | |
# this can be used to choose specific columns of interests | |
DF[complete.cases(DF[, 'y']),] | |
# to simplily omit all rows containing NA, use na.omit | |
na.omit(DF) | |
m <- as.matrix(DF) | |
na.omit(m) | |
options("na.action") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment