Last chance! 50% off unlimited learning
Sale ends in
These functions allow you to select variables based on their names.
starts_with()
: starts with a prefix
ends_with()
: ends with a prefix
contains()
: contains a literal string
matches()
: matches a regular expression
num_range()
: a numerical range like x01, x02, x03.
one_of()
: variables in character vector.
everything()
: all variables.
current_vars()starts_with(match, ignore.case = TRUE, vars = current_vars())
ends_with(match, ignore.case = TRUE, vars = current_vars())
contains(match, ignore.case = TRUE, vars = current_vars())
matches(match, ignore.case = TRUE, vars = current_vars())
num_range(prefix, range, width = NULL, vars = current_vars())
one_of(..., vars = current_vars())
everything(vars = current_vars())
A string.
If TRUE
, the default, ignores case when matching
names.
A character vector of variable names. When called from inside
select()
these are automatically set to the names of the
table.
A prefix that starts the numeric range.
A sequence of integers, like 1:5
Optionally, the "width" of the numeric range. For example, a range of 2 gives "01", a range of three "001", etc.
One or more character vectors.
An integer vector giving the position of the matched variables.
# NOT RUN {
iris <- tbl_df(iris) # so it prints a little nicer
select(iris, starts_with("Petal"))
select(iris, ends_with("Width"))
select(iris, contains("etal"))
select(iris, matches(".t."))
select(iris, Petal.Length, Petal.Width)
select(iris, everything())
vars <- c("Petal.Length", "Petal.Width")
select(iris, one_of(vars))
# }
Run the code above in your browser using DataLab