factorize: Conditionally convert vectors to factors

View source: R/factorize.R

factorizeR Documentation

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, ...)

## Default S3 method:
factorize(x, ...)

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

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

## S3 method for class '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

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

mosaic documentation built on May 29, 2024, 5:27 a.m.