Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

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

## 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

Project MOSAIC Statistics and Mathematics Teaching Utilities

v1.8.3
GPL (>= 2)
Authors
Randall Pruim [aut, cre], Daniel T. Kaplan [aut], Nicholas J. Horton [aut]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.