as.numfac | R Documentation |
Converts a factor
to a numeric vector
with approximately the
numeric values of its levels
. Hence, the levels
of the
factor
must be numeric values, stored as characters. It uses the method
described in factor
. Use as.numeric
to convert a
factor
to a numeric vector
with integers 1, 2, ... corresponding
to the positions in the list of levels. You can also use fac.recast
to
recode the levels to numeric values. If a numeric
is supplied, it is
left unchanged.
as.numfac(factor)
factor |
The |
A numeric vector
. An NA
will be stored for any value of the factor whose
level is not a number.
Chris Brien
as.numeric
, fac.recast
in package dae, factor
.
## set up a factor and convert it to a numeric vector
a <- factor(rep(1:3, 4))
x <- as.numfac(a)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.