Now you can use tidyr 0.5.0's separate_rows
is in place of strsplit
+ unnest
.
For example:
library(tidyr)
(df <- read.table(textConnection("1|a,b,c\n2|a,c\n3|b,d\n4|e,f"), header = F, sep = "|", stringsAsFactors = F))
V1 V2
1 1 a,b,c
2 2 a,c
3 3 b,d
4 4 e,f
separate_rows(df, V2)
Gives:
V1 V2
1 1 a
2 1 b
3 1 c
4 2 a
5 2 c
6 3 b
7 3 d
8 4 e
9 4 f
See reference: https://blog.rstudio.org/2016/06/13/tidyr-0-5-0/