Learn R Programming

insight (version 0.15.0)

data_relocate: Relocate (reorder) columns of a data frame

Description

Relocate (reorder) columns of a data frame

Usage

data_relocate(data, cols, before = NULL, after = NULL, safe = TRUE, ...)

Arguments

data

A data frame to pivot.

cols

A character vector indicating the names of the columns to move.

before, after

Destination of columns. Supplying neither will move columns to the left-hand side; specifying both is an error.

safe

If TRUE, will disregard non-existing columns.

...

Additional arguments passed on to methods.

Value

A data frame with reordered columns.

Examples

Run this code
# NOT RUN {
# Reorder columns
head(data_relocate(iris, cols = "Species", before = "Sepal.Length"))
head(data_relocate(iris, cols = "Species", before = "Sepal.Width"))
head(data_relocate(iris, cols = "Sepal.Width", after = "Species"))
head(data_relocate(iris, cols = c("Species", "Petal.Length"), after = "Sepal.Width"))
# }

Run the code above in your browser using DataLab