Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201919

TidyR Separate: last occurence of underscore [duplicate]

$
0
0

This question already has an answer here:

I have a column with these values:

gene_id
ENSG00000228572.7_PAR_Y_AL954722.1
ENSG00000182378.13_PAR_Y_PLCXD1
ENSG00000223972.5_DDX11L1
ENSG00000243485.5_MIR1302-2HG

I am trying to separate these on the last occurence of underscore _:

library(tidyverse)
expr <- expr %>% 
    separate(gene_id, c("gene_id", "gene_symbol"), sep = "\\_", extra = "merge") %>%
    as.data.frame()

However, this results in:

gene_id gene_symbol
ENSG00000228572.7   PAR_Y_AL954722.1
ENSG00000182378.13  PAR_Y_PLCXD1
ENSG00000223972.5   DDX11L1
ENSG00000243485.5   MIR1302-2HG

Instead, I would like to separate on the last occurence of underscore so that the _PAR_Y piece remains in the gene_id column.


Viewing all articles
Browse latest Browse all 201919

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>