move: Move columns to front/back

Description Usage Arguments Details Value Note Examples

Description

Move specific columns in data.frames to be the first or last columns.

Usage

1
2
3
4
5
6
7

Arguments

df

A data.frame.

...

Comma separated list of unquoted expressions. Used in NSE functions.

cols

A vector of column names to move. Used in SE functions.

Details

moveFront moves columns to be the first columns in a data.frame, moveBack moves columns to be the last columns in a data.frame.

The order of the columns as passed in the arguments will be the same order that the columns will appear in the resulting data.frame, regardless if the front or back functions are called.

moveFront and moveBack are the non-standard evaluation (NSE) versions, while moveFront_ and moveBack_ are the standard evaluation (SE) versions. Look at the examples to see the difference in usage.

Value

A data.frame with the given columns moved either to the beginning or end of the data.frame.

Note

The dplyr package is required for these functions.

If any of the column names given are not valid columns, an error is raised.

Examples

1
2
3
4
5
6
7
df <- data.frame(a = 1:3, b = 4:6, c = 7:9, d = 10:12)
moveFront(df, d)
moveFront(df, d, c)
moveFront(df, c, d)
moveBack(df, b)
moveBack_(df, "a")
moveFront_(df, c("b", "d"))

daattali/rsalad documentation built on Oct. 28, 2019, 12:16 p.m.