| select_all {dplyr} | R Documentation |
These scoped variants of select() and rename() operate on a
selection of variables. The semantics of these verbs have subtle
but important differences:
Selection drops variables that are not in the selection while renaming retains them.
The renaming function is optional for selection but not for renaming.
The _if and _at variants always retain grouping variables for grouped
data frames.
select_all(.tbl, .funs = list(), ...) rename_all(.tbl, .funs = list(), ...) select_if(.tbl, .predicate, .funs = list(), ...) rename_if(.tbl, .predicate, .funs = list(), ...) select_at(.tbl, .vars, .funs = list(), ...) rename_at(.tbl, .vars, .funs = list(), ...)
.tbl |
A |
.funs |
A function |
... |
Additional arguments for the function calls in
|
.predicate |
A predicate function to be applied to the columns
or a logical vector. The variables for which |
.vars |
A list of columns generated by |
Existing grouping variables are always kept in the data frame, even if not included in the selection.
# Supply a renaming function:
select_all(mtcars, toupper)
select_all(mtcars, "toupper")
select_all(mtcars, list(~toupper(.)))
# Selection drops unselected variables:
is_whole <- function(x) all(floor(x) == x)
select_if(mtcars, is_whole, toupper)
select_at(mtcars, vars(-contains("ar"), starts_with("c")), toupper)
# But renaming retains them:
rename_if(mtcars, is_whole, toupper)
rename_at(mtcars, vars(-(1:3)), toupper)
rename_all(mtcars, toupper)
# The renaming function is optional for selection:
select_if(mtcars, is_whole)
select_at(mtcars, vars(-everything()))
select_all(mtcars)