expl_categorical: expl_categorical

Description Usage Arguments Value Examples

View source: R/expl_categorical.R

Description

When given a dataframe object, this function will return a dataframe object with 1 row per level for variable sorted alphabetically.

It will provide: how many rows contain that level and the percentage of that value for that variable.

Usage

1
expl_categorical(df, char.level = 20, num.level = 20)

Arguments

df

dataframe - train set.

char.level

Numeric - exclude character|factor columns if levels > char.level

num.level

Numeric - exclude numeric|integer columns if levels > num.level (NULL discards numeric columns)

Value

a dataframe containing the columns: var [Character]: a character variable level [Character]: a level for that character variable class [Character]: what class is the variable n [Integer]: count of that level perc [Numeric]: percentage of that level

no character columns: "no character or factors" too many levels in all character columns: "no columns with fewer levels than char.level"

Examples

1
2
3
4
5
6
df <- data.frame(pet = rep(c('dog', 'cat', 'horse', 'hamster'), c(40,30,20,10)),
                age = 1:100,
                size = factor(rep(c('Small','Large', NA), c(50,30,20)), levels = c('Small', 'Large'), ordered = TRUE),
                stringsAsFactors = FALSE)
expl_categorical(df, char.level = 3)
expl_categorical(df, char.level = 5)

gloverd2/admr documentation built on Dec. 2, 2020, 11:16 p.m.