ordinal_to_binary: convert a column of categorical covariates into a number of...

ordinal_to_binary_R Documentation

convert a column of categorical covariates into a number of columns with a binary flag for each category

Description

convert a column of categorical covariates into a number of columns with a binary flag for each category

Usage

ordinal_to_binary_(df, col_name, prefix = NULL, overwrite = FALSE)

Arguments

df

data frame

col_name

column name to split into multiple binary flags

prefix

string name if want to specify a prefix to label the binary flag columns other than the original col_name

overwrite

overwrite any existing columns if the newly generated columns share the same name

Examples

library(dplyr)
df <- data_frame(OCC = c(1, 1, 2, 3))
df %>% ordinal_to_binary_("OCC")
df %>% ordinal_to_binary_("OCC", prefix = "OCCASION")

df2 <- data_frame(OCC = c(1, 1, 2, 3), OCC1 = 999)
df2 %>% ordinal_to_binary_("OCC")
df2 %>% ordinal_to_binary_("OCC", overwrite = TRUE)

metrumresearchgroup/PKPDmisc documentation built on Oct. 21, 2022, 9:41 a.m.