R any_vars() Function from dplyr

R any_vars() is a helper function used within the scoped variants of dplyr functions to apply a condition to a subset of columns, and it returns TRUE if the condition is true for any of the selected columns.

Essentially, this function performs a logical OR operation across the columns.




Name Description
.predicate It is a logical condition to be applied to the selected columns.

Return value

It returns the row selection based on whether specified columns satisfy the condition.

Example: Filtering rows

Understanding of any_vars() function from dplyr package


df <- data.frame(
  col1 = c(1, 2, 3),
  col2 = c(4, 5, 6),
  col3 = c(7, 8, 9)

df %>% filter_all(any_vars(. > 7))


   col1  col2  col3
1   2     5     8
2   3     6     9

That’s all!

Leave a Comment