How to Delete Parentheses in a Character String in R (Example Code)
In this article, I’ll show how to delete parentheses in a character string in R.
Example Data
x <- "12(3)4(5)" # Example string in R x # Displaying character string # [1] "12(3)4(5)" |
x <- "12(3)4(5)" # Example string in R x # Displaying character string # [1] "12(3)4(5)"
Example: Extract All Parentheses in a Character String
gsub("[()]", "", x) # Applying gsub() # [1] "12345" |
gsub("[()]", "", x) # Applying gsub() # [1] "12345"
Related Articles
Below, you can find some further resources on topics such as character strings, missing data, and RStudio.