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

Description Usage Arguments Examples

Description

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

Usage

1
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

1
2
3
4
5
6
7
8
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)

PKPDmisc documentation built on April 14, 2020, 5:49 p.m.