删除“。”之后的部分字符串。我正在使用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] "" "" "" "" "" ""但正如您所看到的,这不是这个变量的正确方法。谁能帮我这个?
3 回答
紫衣仙女
TA贡献1839条经验 获得超15个赞
你只需要逃避这段时间:
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"
慕斯王
TA贡献1864条经验 获得超2个赞
我们可以假装它们是文件名并删除扩展名:
tools::file_path_sans_ext(a)# [1] "NM_020506" "NM_020519" "NM_001030297" "NM_010281" "NM_011419" "NM_053155"
- 3 回答
- 0 关注
- 606 浏览
添加回答
举报
0/150
提交
取消