View source: R/dataframe_tools.R
sort_cols | R Documentation |
Sorts the columns of a dataframe, and then allows you to pull columns to the start of the dataframe by name.
sort_cols(df, ..., decreasing = FALSE)
df |
(Dataframe) A dataframe. |
... |
(Column names) If you want to manually position columns after they are
sorted, provide unquoted column names here. The columns in |
decreasing |
(Logical) If |
A copy of df
with reordered columns.
Desi Quintans (http://www.desiquintans.com)
colnames(iris)
#> [1] "Sepal.Length" "Sepal.Width" "Petal.Length" "Petal.Width" "Species"
sorted <- sort_cols(iris)
colnames(sorted)
#> [1] "Petal.Length" "Petal.Width" "Sepal.Length" "Sepal.Width" "Species"
reverse <- sort_cols(iris, decreasing = TRUE)
colnames(reverse)
#> [1] "Species" "Sepal.Width" "Sepal.Length" "Petal.Width" "Petal.Length"
manual <- sort_cols(iris, Species)
colnames(manual)
#> [1] "Species" " Petal.Length" "Petal.Width" "Sepal.Length" "Sepal.Width"
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.