Learn R Programming

mosaic (version 1.9.1)

factorize: Conditionally convert vectors to factors

Description

A generic function and several instances for creating factors from other sorts of data. The primary use case is for vectors that contain few unique values and might be better considered as factors. When applied to a data frame, this is applied to each variable in the data frame.

Usage

factorize(x, ...)

# S3 method for default factorize(x, ...)

# S3 method for numeric factorize(x, max.levels = 5L, ...)

# S3 method for character factorize(x, max.levels = 5L, ...)

# S3 method for data.frame factorize(x, max.levels = 5L, ...)

factorise(x, ...)

Arguments

x

an object

...

additional arguments (currently ignored)

max.levels

an integer. Only convert if the number of unique values is no more than max.levels.

Examples

Run this code
data(KidsFeet, package="mosaicData")
str(KidsFeet)
factorize(KidsFeet$birthyear)
str(factorize(KidsFeet))
# alternative spelling
str(factorise(KidsFeet))

Run the code above in your browser using DataLab