[英]Duplicating and splitting tab- and semicolon-delimited csv file
I have a .csv file that is tab-delimited with the following data:我有一个以制表符分隔的 .csv 文件,其中包含以下数据:
Column1 Column2 Column3 Column4
123 a v; w t
456 b x; y; z u
I would like to split items within column3 separated by the semicolon ;我想拆分 column3 中以分号分隔的项目; into individual rows and duplicate the other information that belongs to its row.
并复制属于其行的其他信息。
Column1 Column2 Column3 Column4
123 a v t
123 a w t
456 b x u
456 b y u
456 b z u
I am new to using R and will greatly appreciate some ideas on how to perform this.我是使用 R 的新手,非常感谢有关如何执行此操作的一些想法。 Thank you!
谢谢!
Does this work:这是否有效:
library(dplyr)
library(tidyr)
df %>% separate_rows(Column3, sep = '; ')
# A tibble: 5 x 4
Column1 Column2 Column3 Column4
<int> <chr> <chr> <chr>
1 123 a v t
2 123 a w t
3 456 b x u
4 456 b y u
5 456 b z u
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.