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