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
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