unfactorize: Unfactorize

unfactorizeR Documentation

Unfactorize

Description

Coerce all columns in the object from factor.

Usage

unfactorize(object, ...)

## S4 method for signature 'factor'
unfactorize(object)

## S4 method for signature 'DFrame'
unfactorize(object, j = NULL)

## S4 method for signature 'data.frame'
unfactorize(object, j = NULL)

Arguments

object

Object.

j

vector. Column names or positions to evaluate.

...

Additional arguments.

Value

Modified object, with factor coerced back to atomic vector.

Note

Updated 2023-09-20.

See Also

  • Warning section of help("factor").

  • R FAQ 7.10: How do I convert factors to numeric?

  • stringsAsFactors for read.table and data.frame.

  • https://stackoverflow.com/questions/3418128/

  • forcats package.

Examples

## factor ====
object <- as.factor(c(100L, 100L, 101L, 101L))
## Coercion with `as.numeric` or `as.integer` don't work the way we want.
print(as.numeric(object))
print(as.integer(object))
object <- factorize(object)
print(object)

## DFrame ====
object <- S4Vectors::DataFrame(
    "a" = as.factor(c(100L, 100L, 101L, 101L)),
    "b" = as.factor(c("a", "b", "a", "b"))
)
print(object)
object <- unfactorize(object)
print(object)

acidgenomics/brio documentation built on Feb. 1, 2024, 11:47 a.m.