-1

I like to remove rows contain chr1_ _random and then sort my data based on chr and start columns:

data:

Coordinates                                         chr     start       end                                              
chr1_gl000191_random:25220-31247 chr1_gl000191_random     25220     31247                                 
chr1_gl000191_random:28291-31301 chr1_gl000192_random     28291     31301  
chr1:100015775-100016525                         chr1 100015775 100016525       
chr1:10001650-10004925                           chr1  10001650  10004925

out put:

Coordinates                                         chr     start       end                                               
chr1:10001650-10004925                           chr1  10001650  10004925
chr1:100015775-100016525                         chr1 100015775 100016525

Thank you for any suggestion in advance!

star
  • 743
  • 1
  • 7
  • 19

1 Answers1

1

For removing rows contain chr1_ _random use

data <- data[grepl("chr1\\_.*\\_random", data$chr) == FALSE,]

Then for sorting use

attach(data)
data = data[order(start, end),]
detach(data)
  • @ Virguez: Thanks ! but sorting method does not work and I get this errore: Error in detach(data) : invalid 'name' argument – star Jun 26 '18 at 14:44