keep only unique elements in string in r

后端 未结 2 1435
面向向阳花
面向向阳花 2021-01-29 10:01

In genomics research, you often have many strings with duplicate gene names. I would like to find an efficient way to only keep the unique gene names in a string. This is an exa

2条回答
  •  春和景丽
    2021-01-29 10:57

    An alternative is doing

    unique(unlist(strsplit(genes, ";")))
    #[1] "GSTP1" "APC"
    

    Then this should give you the answer

    paste(unique(unlist(strsplit(genes, ";"))), collapse = ";")
    #[1] "GSTP1;APC"
    

提交回复
热议问题