Learn R Programming

fifer (version 1.1)

unfactor: Convert a factor to a character (or number)

Description

Analogous to the function factor, unfactor will convert a factor to a character or integer

Usage

unfactor(x, levels, labels, numeric = FALSE)

Arguments

x
The vector of factors you wish to replace
levels
A numeric vector of the values that will replace the factors
labels
A character vector of the values to be replaced
numeric
Should the labels be returned (i.e., characters)? Or the numbers?

Value

A numeric or character vector

See Also

factor

Examples

Run this code
	#### create sample of male/female participants (at random)
x = as.factor(sample(c("Male", "Female"), 12, replace=TRUE))
unfactor(x, levels=c(0,1), labels=c("Male", "Female"))

Run the code above in your browser using DataLab