Learn R Programming

misty (version 0.6.7)

df.move: Move Variable(s) in a Data Frame

Description

This function moves variables to a different position in the data frame, i.e., changes the column positions in the data frame. By default, variables specified in the first argument ... are moved to the first position in the data frame specified in the argument data.

Usage

df.move(..., data = NULL, before = NULL, after = NULL, first = TRUE, check = FALSE)

Value

Returns the data frame in data with columns in a different place.

Arguments

...

an expression indicating the variable names in data to move. Note that the operators ., +, -, ~, :, ::, and ! can also be used to select variables, see Details in the df.subset function.

data

a data frame.

before

a character string indicating a variable in data. Variable(s) specified in ... are moved to the left-hand side of this variable.

after

a character string indicating a variable in data. Variable(s) specified in ... are moved to the right-hand side of this variable.

first

logical: if TRUE (default), variable(s) specified in ... will be moved to the first position in 'data', if FALSE, variable(s) specified in ... will be moved to the last position in 'data'.

check

logical: if TRUE (default), argument specification is checked.

Author

Takuya Yanagida takuya.yanagida@univie.ac.at

References

Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988) The New S Language. Wadsworth & Brooks/Cole.

See Also

df.duplicated, df.merge, df.rbind, df.rename, df.sort, df.subset

Examples

Run this code
# Example 1: Move variables 'hp' and 'am' to the first position
df.move(hp, am, data = mtcars)

# Example 2: Move variables 'hp' and 'am' to the last position
df.move(hp, am, data = mtcars, first = FALSE)

# Example 3: Move variables 'hp' and 'am' to the left-hand side of 'disp'
df.move(hp, am, data = mtcars, before = "disp")

# Example 4: Move variables 'hp' and 'am' to the right-hand side of 'disp'
df.move(hp, am, data = mtcars, after = "disp")

Run the code above in your browser using DataLab