convert {anchors}R Documentation

Convert factor or character variables into integers

Description

Use convert to transform factor or character variables into ordered integer values prior to using anchors or chopit.

Usage

convert(vars, data, order, ...)

Arguments

vars

a character vector identifying the variables in data to be converted to integers.

data

data frame containing vars.

order

a character vector identifying the factor levels to be converted to integers, in increasing order. If NA is omitted here (default), NA values are retained as NA. If NA is included, then NA values are converted to the the last category (which can be adjusted via ....

...

addtional arguments passed to factor.

Value

A data frame, with the character or factor variables identified in vars replaced by integers.

Author(s)

Olivia Lau

References

Jonathan Wand, Gary King and Olivia Lau. (2007) “Anchors: Software for Anchoring Vignettes”. Journal of Statistical Software. Forthcoming. copy at http://wand.stanford.edu/research/anchors-jss.pdf

See Also

anchors, chopit

Examples


set.seed(391)
a <- sample(c("net gain", "little effect",  "modest loss", "major loss"),
            20, replace=TRUE)

dta <- as.data.frame( list(ncost=a) , stringsAsFactors  = FALSE)
print(dta)

newdat <- convert("ncost", data = dta, 
                  order = c("net gain", "little effect",  "modest loss", "major loss"))

print(newdat)


[Package anchors version 3.0-8 Index]