删除“."之后的部分字符串 [英] Remove part of string after "."
本文介绍了删除“."之后的部分字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用 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?
推荐答案
你只需要转义句点:
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"
这篇关于删除“."之后的部分字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文