簡體   English   中英

在單詞之前(在R中)從字符串中刪除字符

[英]Remove characters from a string BEFORE a word (in R)

我是這個社區的新手,我想問這個問題(我沒有找到任何可以幫助我的問題)。

我有這個字符串:

{name:GTP hydrolysis and joining of the 60S ribosomal subunit,description:Hydrolysis of eIF2-GTP occurs after the Met-tRNAi has recognized the AUG. This reaction is catalyzed by eIF5 (or eIF5B) and is thought to cause dissociation of all other initiation factors and allow joining of the large 60S ribosomal subunit. The 60S subunit joins - a reaction catalyzed by eIF5 or eIF5B - resulting in a translation-competent 80S ribosome. Following 60S subunit joining, eIF5B hydrolyzes its GTP and is released from the 80S ribosome, which is now ready to start elongating the polypeptide chain.,url:https://reactome.org/PathwayBrowser/#/R-HSA-72706,sameAs:null,version:62,keywords:[Pathway],creator:[],includedInDataCatalog:{url:https://reactome.org,name:Reactome,@type:DataCatalog},distribution:[{contentUrl:https://reactome.org/ContentService/exporter/sbml/72706.xml,fileFormat:SBML,@type:DataDownload},{contentUrl:https://reactome.org/ReactomeRESTfulAPI/RESTfulWS/sbgnExporter/72706,fileFor... <truncated>

這非常混亂,我想刪除單詞描述之前的所有字符。 所以最終會像這樣:

description:Hydrolysis of eIF2-GTP occurs after the Met-tRNAi has recognized the AUG. This reaction is catalyzed by eIF5 (or eIF5B) and is thought to cause dissociation of all other initiation factors and allow joining of the large 60S ribosomal subunit. The 60S subunit joins - a reaction catalyzed by eIF5 or eIF5B - resulting in a translation-competent 80S ribosome. Following 60S subunit joining, eIF5B hydrolyzes its GTP and is released from the 80S ribosome, which is now ready to start elongating the polypeptide chain.,url:https://reactome.org/PathwayBrowser/#/R-HSA-72706,sameAs:null,version:62,keywords:[Pathway],creator:[],includedInDataCatalog:{url:https://reactome.org,name:Reactome,@type:DataCatalog},distribution:[{contentUrl:https://reactome.org/ContentService/exporter/sbml/72706.xml,fileFormat:SBML,@type:DataDownload},{contentUrl:https://reactome.org/ReactomeRESTfulAPI/RESTfulWS/sbgnExporter/72706,fileFor... <truncated>

提前致謝!

您應該使用正則表達式方法,以便可以處理不同數量的前導字符:

a <- "{name:GTP hydrolysis and joining of the 60S ribosomal subunit,description:Hydrolysis of eIF2-GTP occurs after the Met-tRNAi has recognized the AUG. This reaction is catalyzed by eIF5 (or eIF5B) and is thought to cause dissociation of all other initiation factors and allow joining of the large 60S ribosomal subunit. The 60S subunit joins - a reaction catalyzed by eIF5 or eIF5B - resulting in a translation-competent 80S ribosome. Following 60S subunit joining, eIF5B hydrolyzes its GTP and is released from the 80S ribosome, which is now ready to start elongating the polypeptide chain.,url:https://reactome.org/PathwayBrowser/#/R-HSA-72706,sameAs:null,version:62,keywords:[Pathway],creator:[],includedInDataCatalog:{url:https://reactome.org,name:Reactome,@type:DataCatalog},distribution:[{contentUrl:https://reactome.org/ContentService/exporter/sbml/72706.xml,fileFormat:SBML,@type:DataDownload},{contentUrl:https://reactome.org/ReactomeRESTfulAPI/RESTfulWS/sbgnExporter/72706,fileFor..."

gsub('(.*)description:','', a)

您可以使用str_extractstringr

library(stringr)
str_extract(text, "description:(?s)(.*$)")

"description:Hydrolysis of eIF2-GTP occurs after the ...

那這個呢

library(stringr)
yourData$yourColumn <- str_sub(yourData$yourColumn, start=62)  # hope I've counted right!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM