as.numeric_factor: Numeric factor to numeric vector

View source: R/helpers.R

as.numeric_factorR Documentation

Numeric factor to numeric vector

Description

Converts a factor with numeric levels to a numeric vector, using the values of the levels.

Usage

as.numeric_factor(x, keepNA = FALSE, sortUnique = FALSE)

Arguments

x

A factor based on numeric values.

keepNA

Keep NA values (TRUE), or remove them (default = FALSE)

sortUnique

Should the unique character values be sorted? (default = FALSE)

Value

A numeric vector with factor levels as names.

Examples


f <- factor(round(runif(10,0,9)))
as.numeric_factor(f)

# Add NAs
f <- factor(c(round(runif(9,0,9)),NA))
as.numeric_factor(f)
as.numeric_factor(f, keepNA = TRUE)



FredHasselman/casnet documentation built on April 20, 2024, 3:05 p.m.