combine_cols | R Documentation |
Combines two columns into one. The name of the first column is used for the new column, the second column is removed. Used for cases where different versions of the same variable exist that have to be combined before computing a summary score.
combine_cols(data, col_1, col_2, name = NULL, keep_other = TRUE)
data |
tbl. Data frame containing the columns to be summarized. |
col_1 |
character. The name of the first variable/column. |
col_2 |
character. The name of the second variable/column. |
name |
character. The name of the field with the combined data.
By default, |
keep_other |
logical. Whether to combine the combined column with the input data frame (Default: TRUE). |
tbl. The input data frame with the combined column and the second
column removed. The name of the combined column is the same as col_1
,
or user-specified in the name
argument.
data <- tibble::tibble(
var_id = c("A", "B", "C"),
var_orig = c(1, NA, 3),
var_alt = c(NA, 2, 4)
)
data |>
combine_cols(
col_1 = "var_orig",
col_2 = "var_alt"
)
data |>
combine_cols(
"var_orig",
"var_alt",
name = "out"
)
data |>
combine_cols(
"var_orig",
"var_alt",
name = "out",
keep_other = FALSE
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.