moveMe: Reorders the Contents of a Vector

Description Usage Arguments Details Value Author(s) References Examples

View source: R/moveMe.R

Description

Shuffle the order of a vector around using natural language statements.

Usage

1
moveMe(invec, movecommand)

Arguments

invec

The input vector

movecommand

The command that describes how you want to shuffle the vector. See Details.

Details

This can be a useful function for reordering the columns of a data.frame or data.table in a convenient manner. In such cases, the invec would be names(your_data_frame). When using data.tables, remember to use setcolorder to avoid copying.

The movecommand argument is specified in the form of "a, b before f". The positions to move are:

Multiples are allowed:

Value

A vector.

Author(s)

Ananda Mahto

References

http://stackoverflow.com/a/18420673/1270695

Examples

1
2
3
4
5
6
7
myvec <- letters[1:10]
myvec
moveMe(myvec, "a last; b, e, g before d; c first; h after j")

x <- names(mtcars)
x
moveMe(x, "hp first; cyl after drat; vs, am, gear before mpg; wt last")

mrdwab/SOfun documentation built on June 20, 2020, 6:15 p.m.