convert {anchors} | R Documentation |
Use convert
to transform factor or character variables into
ordered integer values prior to using anchors
or
chopit
.
convert(vars, data, order, ...)
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 . |
A data frame, with the character or factor variables identified in vars
replaced by integers.
Olivia Lau
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
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)