filter_any: Keep rows that match any condition

View source: R/tidy_like.R

filter_anyR Documentation

Keep rows that match any condition

Description

Keep rows that match any condition

Usage

filter_any(
  df,
  ...,
  patterns,
  invert = FALSE,
  fixed = FALSE,
  ignore.case = FALSE
)

Arguments

df

A data frame, data frame extension (e.g. a tibble),

...

<data-masking> A variable in .data

patterns

A vector of patterns with which the variable will be compared with grepl

invert

logical. If TRUE return rows for elements that do not match.

fixed

logical. If TRUE, pattern is a string to be matched as is. Overrides all conflicting arguments

ignore.case

logical. if FALSE, the pattern matching is case sensitive and if TRUE, case is ignored during matching.

Value

The filter_any() function is used to subset the rows of .data, applying the patterns to the variable (...) to determine which rows should be retained.

Examples


require(dplyr, quietly = TRUE, warn.conflicts = FALSE)

my_cars <- c("mazda", "Merc 2.*")
mtcars %>%
  mutate(car = row.names(.)) %>%
  filter_any(car, patterns = my_cars, ignore.case = T) %>%
  select(-car)

starwars %>% data.frame() %>%
  filter_any(species,patterns = c("human","droid"), ignore.case = T, invert = T) %>%
  select(name, species) %>%
  arrange(species, name)

JahNorr/orrr documentation built on Jan. 29, 2025, 5:11 p.m.