【发布时间】:2020-10-23 10:29:08
【问题描述】:
如果我的数据类似于这样:
Variable 1 Variable 2 Variable 3
1 Red|Blue 0|1 1|0
2 Blue|Red 1|0 0|1
3 Green|Red 0|1 1|0
4 Yellow|Blue 1|0 0|1
我可以根据“|”使用什么来分隔?像这样的:
Variable 1 Variable 2 Variable 3
1 Red 0 1
2 Blue 1 0
3 Blue 1 0
4 Red 0 1
5 Green 0 1
6 Red 1 0
7 Yellow 1 0
8 Blue 0 1
【问题讨论】:
-
查看
tidyr::separate_rows()。例如,separate_rows(df, everything(), sep = "\\|")