R 数据拆分到列
转自:https://mp.weixin.qq.com/s/tuEuAJr3MJ-M5BFr70CJbA
提问:根据第二列分号中的分隔符进行拆分后变成4列
options(stringsAsFactors = F)
a=data.frame(x=c('A','B','C'),
y=c('TP53','KCNMA1;RP11-443A13.5','BRCA1'))
a
do.call(rbind,lapply(1:nrow(a), function(i){
x=as.character(a[i,])
return(data.frame(sample=x[1],
gene=unlist(strsplit(x[2],";")[[1]])))
}))