to.factor: Convert columns to factors

View source: R/to.factor.R

to.factorR Documentation

Convert columns to factors

Description

Loops through columsn in dataframe and coerces them to type "factor".

Usage

to.factor(df, id = NULL)

Arguments

df

a matrix or dataframe.

id

a vector specifying the columns (by name or index) to be converted. The default will convert all columns.

Value

A dataframe

Author(s)

Jason Grafmiller

See Also

as.factor, is.factor, to.numeric

Examples

df <- mtcars
summary(df)

df <- to.factor(df, c("cyl", "gear", "carb"))
# or alternatively
# df <- to.factor(df, c(2, 10:11))
summary(df)

jasongraf1/JGmisc documentation built on July 8, 2024, 6:50 a.m.