I have a data frame with strings under a variable with the |
character. What I want is to remove anything downstream of the |
character.
For ex
You have to scape |
by adding \\|
. Try this
> gsub("\\|.*$", "", string)
[1] "heat-shock protein hsp70, putative "
where string
is
string <- "heat-shock protein hsp70, putative | location=Ld28_v01s1:1091329-1093293(-) | length=654 | sequence_SO=chromosome | SO=protein_coding"
This alternative remove the space at the end of line in the output
gsub("\\s+\\|.*$", "", string)
[1] "heat-shock protein hsp70, putative"