dummy_encoder: Dummy Encoder function to encode multiple columns at once

Description Usage Arguments Value Examples

View source: R/dummycoder.R

Description

This function has been designed to encode multiple columns at once and allows the user to specify whether to drop the reference columns or retain them in the data

Usage

1
dummy_encoder(df, columns, map_fn = furrr::future_map, remove_original = TRUE)

Arguments

df

- data.frame object to pass to the function

columns

- vector of columns to be encoded for dummy encoding

map_fn

- choice of mapping function purrr:map or furr::future_map accepted

remove_original

- remove the variables that the dummy encodings are based off

Value

A tibble containing the dummy encodings

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
## Not run: 
#Use the NHSR stranded dataset
df <- NHSRdatasets::stranded_data
#Create a function to select categorical variables
sep_categorical <- function(df){
 cats <- df %>%
   dplyr::select_if(is.character)
 return(cats)
}
cats <- sep_categorical(df) %>%
 dplyr::select(-c(admit_date))
#Dummy encoding
columns_vector <- c(names(cats))
dummy_encodings <- dummy_encoder(cats, columns_vector)
glimpse(dummy_encodings)

## End(Not run)

ConfusionTableR documentation built on Dec. 11, 2021, 10:07 a.m.