Converts an object to numeric by first coercing it to a factor and then
to numeric. This is useful whenever a categorical or character variable
needs a purely numeric stand-in – for example, as input to functions
that require numeric data (distance calculations, correlation matrices,
some modelling routines), or to obtain a compact, deterministic
small-integer code for an ordinal variable by passing an explicit
levels order.
Arguments
- x
a vector to be converted.
- ...
additional arguments passed to
factor().
Details
This function is a shorthand for as.numeric(factor(x, ...)).
Note that the resulting numeric values correspond to the internal
factor levels, not the original numeric values. In particular, for
character vectors holding numbers the codes follow the alphabetical
level order (see the last example) – use
as.numeric(as.character(x)) to recover the values themselves.
See also
Other data.recode:
asBinary(),
combLevels(),
dummy(),
mReplace(),
recodeX(),
revCode(),
stringsAsFactors()
