Missing Values for Variables

Hello Everyone,
is there a tidyverse syntax to check for missing values for all variables at once instead of 1 by1. I used the below code. However, searching each column 1:1 seems a bit tedious. I am just wondering if there is an easier way to accomplish this all at once. Maybe not but I figured I would ask. Thanks in advance

is.na(RD_Exp$GENDER). #general-r

Here are a few ways to get information about NA values in a data frame. I am sure there are other methods.

DF <- data.frame(S = c("A", "B", "C", "D"),
                 A = c(1,NA,4, 8),
                 B = c(5, 3, 7, NA))
DF
#>   S  A  B
#> 1 A  1  5
#> 2 B NA  3
#> 3 C  4  7
#> 4 D  8 NA
#which rows have no NA values?
complete.cases(DF)
#> [1]  TRUE FALSE  TRUE FALSE

library(purrr)

#which columns have NA values
MyFunc <- function(x) any(is.na(x)) #returns TRUE if there is an NA
map_lgl(DF, MyFunc)
#>     S     A     B 
#> FALSE  TRUE  TRUE

#For each column which rows have NA
map(DF, function(x) which(is.na(x)))
#> $S
#> integer(0)
#> 
#> $A
#> [1] 2
#> 
#> $B
#> [1] 4

Created on 2020-08-01 by the reprex package (v0.3.0)

Thanks a bunch [FJCC], all three options worked!

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.