How to select rows which has NA in any column in the dataframe in R?
3
0
Entering edit mode
2.2 years ago
Amr ▴ 180

How to select rows which has NA in any column in the dataframe in R?

for example:

enter image description here

dataframe NA R • 2.8k views
ADD COMMENT
3
Entering edit mode
2.2 years ago
LDT ▴ 340

you can use the

library(dplyr)

data %>%
 filter_all(any_vars(is.na(.)))
ADD COMMENT
1
Entering edit mode

filter_all and any_vars are deprecated. Instead use filter(df, if_any(everything(), is.na)).

ADD REPLY
0
Entering edit mode

Thanks genius

ADD REPLY
1
Entering edit mode
2.2 years ago
zx8754 12k

We could negate complete.cases:

data[ !complete.cases(data), ]
ADD COMMENT
1
Entering edit mode
2.2 years ago

No NAs:

data[rowSums(apply(data,1,is.na)) == 0,]

Any NAs:

data[rowSums(apply(data,1,is.na)) > 0,]
ADD COMMENT

Login before adding your answer.

Traffic: 1713 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6