Lets say I want to convert columns to numeric if they contain 0, 1, 2, NA and have 3 unique values or less.
Previously I accomplished this with:
outcome_data<- outcome_data %>% dplyr::mutate_if(~any(c(0, 1, 2, NA) %in% .x) & length(unique(as.numeric(.x))) <= 3, as.numeric)
But it's unclear how to refer to .x as the first argument to across() to create a complex if condition. The below prompts an error:
object '.x' not found
outcome_data %>% mutate(across(any(c(0, 1, 2, NA) %in% .x) & length(unique(.x)) < 3), as.numeric))