A dataframe has a column that contains collapsed strings with a seperator "|", for example "a|b" and "a|c|d" may be values in that column. How can these rows be seperated so that all the other column values get repeated?
The number of collapsed strings in the column is not constant.
df <- data.frame(
col1 = 1:3
, col2 = c("a", "b|c", "d|e|f")
)
target_df <- data.frame(
col1 = c(1, 2, 2, 3, 3, 3)
, col2 = letters[1:6]
)
target_df <- df %>% ?