Skip to contents

Coerce all columns in the object to factor (i.e. stringsAsFactors).

Usage

factorize(object, ...)

# S4 method for DFrame
factorize(object, j = NULL)

# S4 method for atomic
factorize(object)

# S4 method for data.frame
factorize(object, j = NULL)

# S4 method for factor
factorize(object)

Arguments

object

Object.

j

vector. Column names or positions to evaluate.

...

Additional arguments.

Value

Modified object. All columns will be coerced to factor.

Note

Updated 2023-09-20.

See also

  • Legacy stringsAsFactors approach for data.frame import.

Examples

## DFrame ====
object <- S4Vectors::DataFrame(
    "a" = c("a", "b", "c", "d"),
    "b" = c("a", "a", "b", "b"),
    "c" = c(1L, 2L, 3L, 4L),
    "d" = c(1L, 2L, 1L, 2L),
    "e" = c(TRUE, TRUE, FALSE, FALSE),
    row.names = c("A", "B", "C", "D")
)
object <- factorize(object)
print(object)
#> DataFrame with 4 rows and 5 columns
#>             a        b         c        d         e
#>   <character> <factor> <integer> <factor> <logical>
#> A           a        a         1        1      TRUE
#> B           b        a         2        2      TRUE
#> C           c        b         3        1     FALSE
#> D           d        b         4        2     FALSE