I have a dataset and I want to replace NAs with empty string in those columns where the number of missing values is greater or equal to n
. For instance, n = 500
.
set.seed(2022)
synthetic <- tibble(
col1 = runif(1000),
col2 = runif(1000),
col3 = runif(1000)
)
na_insert <- c(sample(nrow(synthetic), 500, replace = FALSE))
synthetic[na_insert, 1] <- NA
What I am trying to do and eventually fail:
synthetic %>%
mutate(across(everything(), ~ replace_na(sum(is.na(.x)) >= 500, "")))
What am I doing wrong in this primitive exercise?