dfFactorize: Factorize data.frame

Description Usage Arguments Details Value Note Examples

View source: R/dfFactorize.R

Description

Convert character columns in a data.frame to factors.

Usage

1
dfFactorize(df, only = c(), ignore = c())

Arguments

df

A data.frame.

only

A vector of column names. Only convert these columns to factors.

ignore

A vector of column names. Do not convert these columns.

Details

Given a data.frame, convert character columns to factors. By default, all character columns are converted, but the user can specify which columns to convert or to not convert.

Value

A data.frame with all character columns (or only a subset of them if the parameters were set) converted to factors.

Note

If any of the names in only or ignore are not valid columns, an error is raised.

Only one of only or ignore can be used in a single call.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
df <- data.frame(a = 1:3, b = letters[1:3], c = LETTERS[1:3],
                 stringsAsFactors = FALSE)
str(df)
str(dfFactorize(df))
str(dfFactorize(df, only = "b"))
str(dfFactorize(df, ignore = "b"))
str(dfFactorize(df, ignore = c("b", "c")))
str(dfFactorize(df, only = c("a")))

# The following examples result in errors
## Not run: str(dfFactorize(df, only = c("z")))
## Not run: str(dfFactorize(df, only = "b", ignore = "c"))

daattali/rsalad documentation built on Oct. 28, 2019, 12:16 p.m.