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

Example: Extract All Parentheses in a Character String

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.

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.
You need to agree with the terms to proceed

Menu
Top