Superseded
separate_rows()
has been superseded by separate_longer_delim()
.
If a column contains observations with multiple delimited values, separate them each into their own row.
separate_rows(.df, ..., sep = "[^[:alnum:].]+", convert = FALSE)
A data.frame or data.table
Columns to separate across multiple rows. tidyselect
compatible
Separator delimiting collapsed values
If TRUE, runs type.convert()
on the resulting column.
Useful if the resulting column should be type integer/double.
df <- data.table(
x = 1:3,
y = c("a", "d,e,f", "g,h"),
z = c("1", "2,3,4", "5,6")
)
separate_rows(df, y, z)
#> # A tidytable: 6 × 3
#> x y z
#> <int> <chr> <chr>
#> 1 1 a 1
#> 2 2 d 2
#> 3 2 e 3
#> 4 2 f 4
#> 5 3 g 5
#> 6 3 h 6
separate_rows(df, y, z, convert = TRUE)
#> # A tidytable: 6 × 3
#> x y z
#> <int> <chr> <int>
#> 1 1 a 1
#> 2 2 d 2
#> 3 2 e 3
#> 4 2 f 4
#> 5 3 g 5
#> 6 3 h 6