I want to insert a new column in data.frame whose value is TRUE if there is at least one invalid value in the row and FALSE otherwise.
For this problem applyis an ideal use case:
EDIT - Added Example
tab <- data.frame(a = 1:10, b = c(NA, letters[2:10]), c = c(LETTERS[1:9], NA))
tab$missing <- apply(tab, 1, function(x) any(is.na(x)))
However, I downloaded the strict package and received this error:apply() coerces X to a matrix so is dangerous to use with data frames.Please use lapply() instead.
I know that I can safely ignore this error, however I was wondering if there is a way to encode it using one of the tidyverse packages in a simple way . I tried unsuccessfully with dplyr:
tab %>%
rowwise() %>%
mutate(missing = any(is.na(.), na.rm = TRUE))
source
share