Learn R Programming

useful (version 1.2.6)

moveToFront: moveToFront

Description

Rearranges column order by moving specified columns to the front or back.

Usage

moveToFront(data, cols)

moveToBack(data, cols)

Value

A data.frame with the columns in the right order

Arguments

data

data.frame

cols

Character vector specifying the columns to be moved to the front or back

Author

Jared P. Lander

Details

Rearranges column order by moving specified columns to the front or back.

Examples

Run this code
theDF <- data.frame(A=1:10, B=11:20, C=1:10, D=11:20)
moveToFront(theDF, c('B', 'C'))
moveToFront(theDF, c('C', 'B'))
moveToFront(theDF, c('C', 'C'))
moveToBack(theDF, c('C', 'C'))
moveToBack(theDF, c('C', 'B'))
moveToBack(theDF, c('C', 'C'))

Run the code above in your browser using DataLab