I have this dataframe in R
df <- structure(list(S.No = c(1L, 2L, 3L, 8L, 5L, 6L), A = c(8L, 8L,
5L, 2L, NA, 3L), B = c(5L, 8L, 8L, 2L, NA, 3L), C = c("8", "test",
"error", "3", NA, "3"), D = c(5L, 5L, 3L, 3L, NA, 8L), E = c("test",
"8", "8", "error", NA, "3")), class = "data.frame", row.names = c(NA,
-6L))
I need to find out if all values of the columns for each row have NA. It needs to be rowwise, but I can't get this to work. This is what I have tried so far
test.vars = c("A","B","C","D","E")
df %>% mutate(null_message = as.numeric(is.na(rowSums(.[test.vars]))))
This works if my columns have only numeric values. So, I tried to do something else:
df %>% mutate(null_message = any(is.na((.[test.vars]))))
but this doesn't work. It shows all rows as TRUE, and I know why. I can use | but it seems bit tedious to do is.na(A) | is.na(B) | is.na(C) | ... . Is there a way I can get this done efficiently?
The expected output is the following:
