Skip to contents

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

Usage

factorize(object, ...)

# S4 method for DataFrame
factorize(object)

# S4 method for data.frame
factorize(object)

Arguments

object

Object.

...

Additional arguments.

Value

Modified object. All columns will be coerced to factor.

Note

Updated 2022-10-24.

See also

  • Legacy stringsAsFactors approach for data.frame import.

Examples

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),
    row.names = c("A", "B", "C", "D")
)
object <- factorize(object)
print(object)
#> DataFrame with 4 rows and 4 columns
#>             a        b         c        d
#>   <character> <factor> <integer> <factor>
#> A           a        a         1        1
#> B           b        a         2        2
#> C           c        b         3        1
#> D           d        b         4        2