dae (version 3.0-32)

as.numfac: Convert a factor to a numeric vector

Description

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.recode to recode the levels to numeric values. If a numeric is supplied, it is left unchanged.

Usage

as.numfac(factor)

Arguments

factor

The factor to be converted.

Value

A numeric vector. An NA will be stored for any value of the factor whose level is not a number.

See Also

as.numeric, fac.recode in package dae, factor.

Examples

Run this code
# NOT RUN {
## set up a factor and convert it to a numeric vector
a <- factor(rep(1:3, 4))
x <- as.numfac(a)
# }

Run the code above in your browser using DataLab