Learn R Programming

Publish (version 2023.01.17)

lazyFactorCoding: Efficient coding of factor levels

Description

This function eases the process of generating factor variables with relevant labels. All variables in a data.frame with less than a user set number of levels result in a line which suggests levels and labels. The result can then be modified for use.

Usage

lazyFactorCoding(data, max.levels = 10)

Value

R-code one line for each variable.

Arguments

data

Data frame in which to search for categorical variables.

max.levels

Treat non-factor variables only if the number of unique values less than max.levels. Defaults to 10.

Author

Thomas Alexander Gerds

Details

The code needs to be copy-and-pasted from the R-output buffer into the R-code buffer. This can be customized for the really efficiently working people e.g. in emacs.

Examples

Run this code
data(Diabetes)
lazyFactorCoding(Diabetes)

Run the code above in your browser using DataLab