View source: R/dthelper-collapse-column.R
collapse.var | R Documentation |
Collapse Multiple Variables into a single Column
collapse.var(df, var = colnames(df), return.conflicts = FALSE)
df |
data.frame object |
var |
Variable to collapse |
return.conflicts |
If set to TRUE and there are conflicts within the input variables, the conflicting rows will be returned |
vector object. If return.conflicts set to TRUE, a list object is returned
df <- data.frame( v1.t1 = c(1:10), v1.t2 = c(1:5, rep(NA, 5)), v2.t1 = c(12,13,14,rep(NA,7)), v2.t2 = c(11:20) ) df$v1 <- collapse.var(df, var = c("v1.t1","v1.t2")) df$v2 <- collapse.var(df, var = c("v2.t1","v2.t2")) conflicts <- collapse.var(df, var = c("v2.t1","v2.t2"), return.conflicts = T) also see <https://msrcodelibrary.netlify.app/2020/06/10/multiple-recoding-and-collapsing-columns/> for step-by-step tutorial.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.