Learn R Programming

tidytable (version 0.5.1)

where: Select variables with a function

Description

This selection helper selects the variables for which a function returns `TRUE`.

Usage

where(fn)

Arguments

fn

A function that returns `TRUE` or `FALSE` (technically, a _predicate_ function). Can also be a purrr-like formula.

Examples

Run this code
# NOT RUN {
iris %>% select.(where(is.factor))

iris %>% select.(where(is.numeric))

## The formula shorthand
# These expressions are equivalent:

iris %>% select.(where(is.numeric))

iris %>% select.(where(function(x) is.numeric(x)))

iris %>% select.(where(~ is.numeric(.x)))

# This shortahand is useful for adding logic inline.
# Here we select all numeric variables whose mean is greater than 3.5:
iris %>%
  select.(where(~ is.numeric(.x) && mean(.x) > 3.5))

# }

Run the code above in your browser using DataLab