If a variable contains observations with multiple delimited values, this separates the values and places each one in its own row.

separate_rows(data, ..., sep = "[^[:alnum:].]+", convert = FALSE)

Arguments

data

A data frame.

...

Specification of columns to separate. Use bare variable names. Select all variables between x and z with x:z, exclude y with -y. For more options, see the select documentation.

sep

Separator delimiting collapsed values.

convert

If TRUE, will run type.convert with as.is = TRUE on new columns. This is useful if the component columns are integer, numeric or logical.

Examples

df <- data.frame( x = 1:3, y = c("a", "d,e,f", "g,h"), z = c("1", "2,3,4", "5,6"), stringsAsFactors = FALSE ) separate_rows(df, y, z, convert = TRUE)
#> x y z #> 1 1 a 1 #> 2 2 d 2 #> 3 2 e 3 #> 4 2 f 4 #> 5 3 g 5 #> 6 3 h 6