as.numfac: Convert a factor to a numeric vector

as.numfacR Documentation

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.recast 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.

Author(s)

Chris Brien

See Also

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

Examples

## set up a factor and convert it to a numeric vector
a <- factor(rep(1:3, 4))
x <- as.numfac(a)

dae documentation built on Aug. 7, 2023, 5:08 p.m.