我有一个小组:
gene n
<chr> <int>
CBLB 434
UBAC2;NA;TM9SF2;GPR18;GPR183 434
ATP6V1G3;PTPRC 379
NA;BCAS1 372
我想用“;”分割多个基因分开的行。所以:
gene n
<chr> <int>
CBLB 434
UBAC2 434
NA 434
TM9SF2 434
GPR18 434
GPR183 434
ATP6V1G3 379
PTPRC 379
NA 372
BCAS1 372
我试过了:
hs %>% rowwise() %>% mutate(gene=unlist(strsplit(gene,";")),n=n)
但它给了我:
Error in mutate_impl(.data, dots) :
Column `gene` must be length 1 (the group size), not 3
有什么想法吗?
这是一个可重现的例子:
structure(list(gene = c("CBLB", "UBAC2;NA;TM9SF2;GPR18;GPR183",
"ATP6V1G3;PTPRC", "NA;BCAS1", "HINT3;NCOA7", "RALGPS2"), IS = c(434L,
434L, 379L, 372L, 372L, 349L)), .Names = c("gene", "n"), row.names = c(NA,
-6L), class = c("tbl_df", "tbl", "data.frame"))