In R, you can split a string using the strsplit
function.
In this example,
str
with a value of "Hello World"
.strsplit
function with a space as the delimiter.str <- 'Hello World'
parts <- strsplit(str, ' ')
print(parts[[1]])
[1] "Hello" "World"
In this example,
str
with a value of "apple,banana,cherry"
.strsplit
function with a comma as the delimiter.str <- 'apple,banana,cherry'
parts <- strsplit(str, ',')
print(parts[[1]])
[1] "apple" "banana" "cherry"
In this tutorial, we learned How to Split a String in R language with well detailed examples.