knitr::opts_chunk$set(echo = TRUE) library(epiuf)
collapseVar take number list variables in character format with any separator (eg. "1|2|3", "1/2/3", "1,2,3"), and retains only one input / row based off hirearchy specified and return numeric variable. If order input is not complete, a warning is given.
# create example dataset for testing df <- data.frame(checkbox_bar = c("0|2", "1|2|3", "3|1|2", "0", "2", "3", "0|1", "2|3", "") ,checkbox_comma = c("0,2", "1,2,3", "3,1,2", "0", "2", "3", "0,1", "2,3", "") ,checkbox_slash = c("0/2", "1/2/3", "3/1/2", "0", "2", "3", "0/1", "2/3", "") )
df$test <- collapseVar(df, checkbox_bar, c(0,1,2,3)) df$test <- collapseVar(df, checkbox_comma, c(0,1,2,3)) df$test <- collapseVar(df, checkbox_slash, c(0,1,2,3))
Expected outcome for each: 0 1 1 0 2 3 0 2 NA
df$test <- collapseVar(df, checkbox_bar, c(0,1,2,3,4))
Expected outcome: 0 1 1 0 2 3 0 2 NA
df$test <- collapseVar(df, checkbox_bar, c(0,2))
Expected outcome: Warning: input order list incomplete, missing 1 3
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.