Move columns to other positions in a data frame
move_columns()
moves one or more columns in a data frame
to another position.
move_columns(data, ..., .before, .after)
data |
A data frame. |
... |
Unquoted names or character vector with names of variables that
should be move to another position. You may also use functions like
|
.before |
Optional, column name or numeric index of the position where
|
.after |
Optional, column name or numeric index of the position where
|
data
, with resorted columns.
If neither .before
nor .after
are specified, the
column is moved to the end of the data frame by default. .before
and .after
are evaluated in a non-standard fashion, so you need
quasi-quotation when the value for .before
or .after
is
a vector with the target-column value. See 'Examples'.
## Not run: data(iris) iris %>% move_columns(Sepal.Width, .after = "Species") %>% head() iris %>% move_columns(Sepal.Width, .before = Sepal.Length) %>% head() iris %>% move_columns(Species, .before = 1) %>% head() iris %>% move_columns("Species", "Petal.Length", .after = 1) %>% head() library(dplyr) iris %>% move_columns(contains("Width"), .after = "Species") %>% head() ## End(Not run) # using quasi-quotation target <- "Petal.Width" # does not work, column is moved to the end iris %>% move_columns(Sepal.Width, .after = target) %>% head() # using !! works iris %>% move_columns(Sepal.Width, .after = !!target) %>% head()
Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.