I've got a dataframe with numeric values between 0 and 1. I'd like to use if_any to do numeric value filtering:
df <- data %>%
filter(if_any(everything(), . > 0.5)
This spits out an error instead:
Error: Problem with `filter()` input `..1`.
ℹ Input `..1` is `if_any(everything(), . < 0.5)`.
x Problem with `across()` input `.fns`.
ℹ `.fns` must be NULL, a function, a formula, or a list of functions/formulas.
Does anyone have a working way of doing this filtering in a tidy way?
You're really close. The erorr message you've gotten is because you forgot the tilde ~
:
df <- data %>%
filter(if_any(everything(), ~ . > 0.5))
I might suggest adding an additional column selection where you only apply your criteria to numeric columns (otherwise you will get an error if you have character or factor variables in your data frame):
df <- data %>%
filter(if_any(where(is.numeric), ~ . > 0.5))