R语言拆分单列separate函数合并unite函数
(2017-11-16 17:38:29)分类: R语言 |
http://www.cnblogs.com/shangfr/p/6110614.html
separate()函数可将一列拆分为多列,一般可用于日志数据或日期时间型数据的拆分,语法如下:
例子:cluster_healthgene_species =
separate(ASD_health_findout,col = V6,into =
separate(data, col, into, sep = “[^[:alnum:]]+”, remove = TRUE,
convert = FALSE, extra = “warn”, fill = “warn”, …)
data:为数据框
col:需要被拆分的列
into:新建的列名,为字符串向量
sep:被拆分列的分隔符
remove:是否删除被分割的列
widesep <- separate(wideunite, information,c("person","grade","score"), sep = "-")
widesep
person grade score
1 Alex 2 78
2 Bob 3 89
3 Cathy 4 88