mvvar: Move Variable in a Data Frame

View source: R/mvvar.r

mvvarR Documentation

Move Variable in a Data Frame

Description

Function to move a variable to a different position in a data frame.

Usage

mvvar(var, where, after=TRUE, data)

Arguments

var

variable to move.

where

variable next to which var will be moved.

after

logical indicating whether to position var after or before variable where (default is after=TRUE).

data

data frame that contains the variables specified above.

Details

The function can be used to move a variable to a different position in a data frame.

Value

A data frame.

Author(s)

Wolfgang Viechtbauer wvb@wvbauer.com

Examples

# illustrative dataset
dat <- data.frame(subj=rep(1:4, each=5),
                  obs = 1:5,
                  age = rep(c(20,31,27,22), each=5),
                  stress = c(2,3,1,4,2, 3,3,3,3,3, 1,1,2,6,4, 1,2,1,3,1))
dat

# move variable age after subj
dat <- mvvar("age", "subj", data=dat)
dat

# move variable obs before age
dat <- mvvar("obs", "age", after=FALSE, data=dat)
dat

wviechtb/esmpack documentation built on April 12, 2025, 9:48 p.m.