Reputation: 8404
I would like to know how could I find a pattern to delete certain part of every string in a vector.
stri<-c("protein mono-ADP-ribosylation (GO:0140289)","negative regulation of viral life cycle (GO:1903901)","viral life cycle (GO:1901)")
More specifically everything inside the parenthesis and the parentheses of course.
Upvotes: 1
Views: 56
Reputation: 1364
Another way you can try
library(stringr)
str_squish(str_replace(stri, "\\(.*\\)", ""))
# [1] "protein mono-ADP-ribosylation" "negative regulation of viral life cycle"
# [3] "viral life cycle"
\\(.*\\)
: matches parenthesis and everything inside.str_squish
: reduces repeated whitespace inside a string.Upvotes: 1
Reputation: 14764
You could try:
gsub('\\s\\(.*', '', stri)
Output:
[1] "protein mono-ADP-ribosylation" "negative regulation of viral life cycle" "viral life cycle"
Upvotes: 2