Deconcatenate delimited column values in a data.frame

deconcat_df2(x, column, split = "[,; |/]+", blank = "", ...)

Arguments

x

data.frame or compatible object

column

character vector with one or more colnames(x) that should be de-concatenated.

split

character pattern used by strsplit() to split multiple values in each column.

blank

character string used to replace entries that would otherwise be zero-length as returned by strsplit().

...

additional arguments are ignored.

Details

This function deconcatenates delimited values in a column of a data.frame by calling strsplit() on column values, and repeating values in all other columns to match lengths() following strsplit().

This function includes a correction for cases where strsplit() would otherwise return zero-length entries, and which would otherwise be dropped from the output. From this function, zero-length entries are replaced with blank="" so these rows are not dropped from the output.

Examples

df <- data.frame(one=c("AB", "BC", "AC"),
   two=c("a,b", "b,c", "a,c"));
deconcat_df2(df, column="two")
#>      one two
#> 1_v1  AB   a
#> 1_v2  AB   b
#> 2_v1  BC   b
#> 2_v2  BC   c
#> 3_v1  AC   a
#> 3_v2  AC   c