move_columns: Move the columns of a dataframe relative to each other.

Description Usage Arguments Value Note See Also Examples

Description

Move the columns of a dataframe relative to each other.

Usage

1
move_columns(x, who, before = NULL, after = NULL)

Arguments

x

a dataframe.

who

A character vector of column names to move, or a logical vector of length names(x), or a vector of indices

before

the column before which to put who: may be character, numeric or NA. If NA, the named columns are moved to the front (before the first column).

after

the column after which to put who: may be character, integer, or NA. If NA, the named columns are moved to the end (after the last column).

Value

A data frame with shuffled columns.

Note

This function has been modified from archived package metrumrg where it was named shuffle.

See Also

https://github.com/cran/metrumrg/blob/master/R/shuffle.R.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
## Not run: 
data(iris)
iris.new <- move_columns(iris, "Species", after = NA) # move species to last column
iris.new <- move_columns(iris, "Species", after = 2)
iris.new <- move_columns(iris, "Species", after = "Sepal.Length")
iris.new <- move_columns(iris, "Species", before = NA) # move species to first column
iris.new <- move_columns(iris, "Species", before = 3)
iris.new <- move_columns(iris, "Species", before = "Petal.Length")

## End(Not run)

Pakillo/pacotools documentation built on May 7, 2019, 11:56 p.m.