Professional Documents
Culture Documents
R - Check If NA Exists in Any Column of R Dataframe Row, Then If So Remove That Row - Stack Overflow
R - Check If NA Exists in Any Column of R Dataframe Row, Then If So Remove That Row - Stack Overflow
Home
R - check if NA exists in any column of r dataframe row, then if so remove that Ask Question
3 na.omit or complete.cases – alistaire Aug 12 '16 at 18:06 Sign up for the digest
Try using complete.cases . 915 Remove rows with all or some NAs
(missing values) in data.frame
26 > df <- data.frame(col1 = c(1, 2, 3, NA, 5), col2 = c('A', 'B', NA, 'C', 'D'), Related
col3 = c(9, NaN, 8, 7, 6))
> df
1377 How to sort a dataframe by multiple
col1 col2 col3
column(s)
1 1 A 9
2 2 B NaN 418 Check existence of directory and create if
3 3 <NA> 8 doesn't exist
4 NA C 7
5 5 D 6 915 Remove rows with all or some NAs
> df[complete.cases(df), ] (missing values) in data.frame
col1 col2 col3
1 1 A 9 37 Subset dataframe by multiple logical
conditions of rows to remove
5 5 D 6
6 Remove rows in dataframe based on three
columns
edited Aug 13 '16 at 2:18 answered Aug 12 '16 at 18:06
Share Edit Follow 797 data.table vs dplyr: can one do something
akrun Sam
well the other can't or does poorly?
634k 22 358 456 1,103 16 21
32 How to remove rows with inf from a
dataframe in R
The complete.cases should be faster than the rest – akrun Aug 13 '16 at 2:18
1 Keep rows in dataframe for the last n
add a comment appearances of a value in a column
na.omit works:
9 na.omit(df)
## team_id athlete_id GP tm_STL tm_TOV player_WS
## 2 13304 75048 1 2 8 0.28563827
## 5 13304 75053 1 2 8 0.03861989
## 6 13304 75060 1 2 8 -0.15530707
It's a little more convenient than complete.cases if you're piping, as it doesn't require another
function to subset like dplyr::filter , magrittr::extract , or [ .
add a comment
Not the answer you're looking for? Browse other questions tagged r or ask your own question.
STACK OVERFLOW PRODUCTS COMPANY STACK EXCHANGE Blog Facebook Twitter LinkedIn Instagram
NETWORK
Questions Teams About
Technology
Jobs Talent Press
Life / Arts
Developer Jobs Directory Advertising Work Here
Culture / Recreation
Salary Calculator Enterprise Legal
Science
Help Privacy Policy
Other
Mobile Terms of Service
site design / logo © 2021 Stack Exchange Inc; user contributions
Disable Responsiveness Contact Us licensed under cc by-sa. rev 2021.2.4.38498