Larry Tomaziefski Larry Tomaziefski - 1 year ago 73
R Question

Trying to replace a () in a string in R using str_replace

I am trying to replace a

in a string using the
function in R but it appears that due that the function is overlooking the
. I am pretty new to coding and R so I imagine that it has something to do with the regular expression of

I just dont know how to make the code identify that I want it to treat the
as regular characters

example string:


Here is the function I am using:


Appreciate the help

Answer Source

\ identify special character

if the parenthesis are in the middle of the string:

text <- "tBodyAcc-mean()-X"
sub("*\\(\\)*", "", text)

if the parenthesis are located anywhere in the string

text <- "tBodyAcc-mean()-X"
sub("\\(\\)", "", text)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download