as_numeric: Converting factors to numeric

Description Usage Arguments Details Value See Also Examples

View source: R/factors.R

Description

Converting factors to numeric

Usage

1
2
3
4
5
6
7
as_numeric(x)

## Default S3 method:
as_numeric(x)

## S3 method for class 'factor'
as_numeric(x)

Arguments

x

a vector

Details

as_numeric() is motivated by the need to convert factors to their numerical representation, rather than their numerically encoded levels. See the examples for differences between base::as.numeric() and as_numeric.

Value

a numeric vector of the same length as x in which each value of x is converted to its actual numeric value

See Also

as_numeric.factor directly follows the suggestion from the Warning section of factor.

Examples

1
2
3
x <- factor(c(-1.9, 0.2, 3.5))
as.numeric(x)
as_numeric(x)

sboysel/boysel documentation built on May 29, 2019, 3:24 p.m.