Description Usage Arguments Details Value Useful filter functions Tidy data Scoped filtering See Also Examples
Use filter()
to choose rows/cases where conditions are true. Unlike
base subsetting with [
, rows where the condition evaluates to NA
are
dropped.
1 |
.data |
A tbl. All main verbs are S3 generics and provide methods
for |
... |
Logical predicates defined in terms of the variables in The arguments in |
.preserve |
when |
Note that dplyr is not yet smart enough to optimise filtering optimisation
on grouped datasets that don't need grouped calculations. For this reason,
filtering is often considerably faster on ungroup()
ed data.
An object of the same class as .data
.
==
, >
, >=
etc
&
, |
, !
, xor()
is.na()
between()
, near()
When applied to a data frame, row names are silently dropped. To preserve,
convert to an explicit variable with tibble::rownames_to_column()
.
The three scoped variants (filter_all()
, filter_if()
and
filter_at()
) make it easy to apply a filtering condition to a
selection of variables.
filter_all()
, filter_if()
and filter_at()
.
Other single table verbs: arrange
,
mutate
, select
,
slice
, summarise
1 2 3 4 5 6 7 8 9 | filter(starwars, species == "Human")
filter(starwars, mass > 1000)
# Multiple criteria
filter(starwars, hair_color == "none" & eye_color == "black")
filter(starwars, hair_color == "none" | eye_color == "black")
# Multiple arguments are equivalent to and
filter(starwars, hair_color == "none", eye_color == "black")
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.