Description Usage Arguments Value Note Examples
move_columns()
moves one or more columns in a data frame
to another position.
1 | 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'.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | ## 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()
|
Sepal.Length Petal.Length Petal.Width Species Sepal.Width
1 5.1 1.4 0.2 setosa 3.5
2 4.9 1.4 0.2 setosa 3.0
3 4.7 1.3 0.2 setosa 3.2
4 4.6 1.5 0.2 setosa 3.1
5 5.0 1.4 0.2 setosa 3.6
6 5.4 1.7 0.4 setosa 3.9
Sepal.Width Sepal.Length Petal.Length Petal.Width Species
1 3.5 5.1 1.4 0.2 setosa
2 3.0 4.9 1.4 0.2 setosa
3 3.2 4.7 1.3 0.2 setosa
4 3.1 4.6 1.5 0.2 setosa
5 3.6 5.0 1.4 0.2 setosa
6 3.9 5.4 1.7 0.4 setosa
Species Sepal.Length Sepal.Width Petal.Length Petal.Width
1 setosa 5.1 3.5 1.4 0.2
2 setosa 4.9 3.0 1.4 0.2
3 setosa 4.7 3.2 1.3 0.2
4 setosa 4.6 3.1 1.5 0.2
5 setosa 5.0 3.6 1.4 0.2
6 setosa 5.4 3.9 1.7 0.4
Sepal.Length Species Petal.Length Sepal.Width Petal.Width
1 5.1 setosa 1.4 3.5 0.2
2 4.9 setosa 1.4 3.0 0.2
3 4.7 setosa 1.3 3.2 0.2
4 4.6 setosa 1.5 3.1 0.2
5 5.0 setosa 1.4 3.6 0.2
6 5.4 setosa 1.7 3.9 0.4
Attaching package: ‘dplyr’
The following objects are masked from ‘package:stats’:
filter, lag
The following objects are masked from ‘package:base’:
intersect, setdiff, setequal, union
Sepal.Length Petal.Length Species Sepal.Width Petal.Width
1 5.1 1.4 setosa 3.5 0.2
2 4.9 1.4 setosa 3.0 0.2
3 4.7 1.3 setosa 3.2 0.2
4 4.6 1.5 setosa 3.1 0.2
5 5.0 1.4 setosa 3.6 0.2
6 5.4 1.7 setosa 3.9 0.4
Sepal.Length Petal.Length Petal.Width Species Sepal.Width
1 5.1 1.4 0.2 setosa 3.5
2 4.9 1.4 0.2 setosa 3.0
3 4.7 1.3 0.2 setosa 3.2
4 4.6 1.5 0.2 setosa 3.1
5 5.0 1.4 0.2 setosa 3.6
6 5.4 1.7 0.4 setosa 3.9
Sepal.Length Petal.Length Petal.Width Sepal.Width Species
1 5.1 1.4 0.2 3.5 setosa
2 4.9 1.4 0.2 3.0 setosa
3 4.7 1.3 0.2 3.2 setosa
4 4.6 1.5 0.2 3.1 setosa
5 5.0 1.4 0.2 3.6 setosa
6 5.4 1.7 0.4 3.9 setosa
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.