separate_rows {tidyr} | R Documentation |
Separate a collapsed column into multiple rows
Description
separate_rows()
has been superseded in favour of separate_longer_delim()
because it has a more consistent API with other separate functions.
Superseded functions will not go away, but will only receive critical bug
fixes.
If a variable contains observations with multiple delimited values,
separate_rows()
separates the values and places each one in its own row.
Usage
separate_rows(data, ..., sep = "[^[:alnum:].]+", convert = FALSE)
Arguments
data |
A data frame. |
... |
< |
sep |
Separator delimiting collapsed values. |
convert |
If |
Examples
df <- tibble(
x = 1:3,
y = c("a", "d,e,f", "g,h"),
z = c("1", "2,3,4", "5,6")
)
separate_rows(df, y, z, convert = TRUE)
# Now recommended
df %>%
separate_longer_delim(c(y, z), delim = ",")
[Package tidyr version 1.3.1 Index]