Specify Two Split Conditions in strsplit() Function in R (Example Code)

In this article, I’ll explain how to set multiple split conditions in the strsplit function in R.

Creation of Example Data

x <- "A_B-C_D-E-F"        # Character string in R
x                         # Display example character string in RStudio console
# [1] "A_B-C_D-E-F"

Example: How to Define Several Arguments in strsplit() Function

strsplit(x, "_|-")        # Using multiple arguments in strsplit function
# [[1]]
# [1] "A" "B" "C" "D" "E" "F"

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