Larry Tomaziefski Larry Tomaziefski - 1 month ago 12
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


\ 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)