删除列中具有某些特定值的行

问题描述 投票:-1回答:1

我想删除包含chr1_ _random的行,然后根据chrstart列对数据进行排序:

数据:

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

出局:

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

感谢您提前提出任何建议!

r r-package bioconductor
1个回答
1
投票

对于删除行包含chr1_ _random使用

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

然后进行分类使用

attach(data)
data = data[order(start, end),]
detach(data)
© www.soinside.com 2019 - 2024. All rights reserved.