我正在使用NCBI参考序列登录号,例如变量a

a <- c("NM_020506.1","NM_020519.1","NM_001030297.2","NM_010281.2","NM_011419.3", "NM_053155.2")  

要从Biomart软件包中获取信息,我需要删除.1,,,,.2等等之后。我通常会使用此代码这样做:

b <- sub("..*", "", a)

# [1] "" "" "" "" "" ""

但是,如您所见,这不是此变量的正确方法。谁能帮我这个?

答案

您只需要逃脱这个时期:

a <- c("NM_020506.1","NM_020519.1","NM_001030297.2","NM_010281.2","NM_011419.3", "NM_053155.2")

gsub("\\..*","",a)
[1] "NM_020506"    "NM_020519"    "NM_001030297" "NM_010281"    "NM_011419"    "NM_053155" 

来自: stackoverflow.com