Learn R Programming

anchors (version 3.0-8)

convert: 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

vars replaced by integers.

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

Run this code

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)

Run the code above in your browser using DataLab