Learn R Programming

iNZightTools (version 1.13.0)

sortVars: Sort data by variables

Description

Sorts a dataframe by one or more variables, and returns the result along with tidyverse code used to generate it.

Usage

sortVars(.data, vars, asc = rep(TRUE, length(vars)))

Value

data.frame with tidyverse code attached

Arguments

.data

a dataframe to sort

vars

a character vector of variable names to sort by

asc

logical, same length as vars. If TRUE (default), sorted in ascending order, otherwise descending.

Author

Owen Jin

See Also

code

Examples

Run this code
sorted <- sortVars(iris, vars = c("Sepal.Width", "Sepal.Length"),
    asc = c(TRUE, FALSE))
cat(code(sorted))
head(sorted)

Run the code above in your browser using DataLab