filter_any | R Documentation |
Keep rows that match any condition
filter_any(
df,
...,
patterns,
invert = FALSE,
fixed = FALSE,
ignore.case = FALSE
)
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. |
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.
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.