本文介绍了删除“."之后的字符串的一部分.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用NCBI参考序列登录号,例如变量a
:
I am working with NCBI Reference Sequence accession numbers like variable a
:
a <- c("NM_020506.1","NM_020519.1","NM_001030297.2","NM_010281.2","NM_011419.3", "NM_053155.2")
要从biomart软件包中获取信息,我需要删除保藏号后的.1
,.2
等.我通常使用以下代码执行此操作:
To get information from the biomart package I need to remove the .1
, .2
etc. after the accession numbers. I normally do this with this code:
b <- sub("..*", "", a)
# [1] "" "" "" "" "" ""
但是如您所见,这不是此变量的正确方法.有人可以帮我吗?
But as you can see, this isn't the correct way for this variable. Can anyone help me with this?
推荐答案
您只需要转义句点即可:
You just need to escape the period:
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"
这篇关于删除“."之后的字符串的一部分.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!