make_long_cols: Create multiple columns from comma-separated column

View source: R/utils-long.R

make_long_colsR Documentation

Create multiple columns from comma-separated column

Description

Given a single column containing multiple comma-separated values, this function will create new columns and split the comma-separated values.

Usage

make_long_cols(df, from, to)

Arguments

df

the dataframe in which the current comma-separated column is stored.

from

a character vector representing the name of the comma-separated column.

to

a character vector of new column names into which the comma-separated column will be split.

Details

This function will create new columns in the data frame but it will not remove the original column (the from column).

Examples

#' @examples
x <- data.table::data.table(
hep_con_ablation_140101 = c("Microwave ablation", "RFA ablation", "Other ablation",
"Microwave ablation,Other ablation", "RFA ablation,Microwave ablation",
"RFA ablation,Other ablation", "RFA ablation,Alcohol ablation", "Alcohol ablation",
"Microwave ablation,Alcohol ablation", "Cryoablation", NA, "RFA ablation,Cryoablation"))

hep_invasive_type_cols <- paste("hep_invasive_type", 1:5, sep = "")

make_long_cols(x, "hep_con_ablation_140101", hep_invasive_type_cols)


dylanrussellmd/nsqipr documentation built on Oct. 13, 2023, 11:01 a.m.