In R, you can split a string by new line using the strsplit
function with the newline character '\n'
.
In this example,
str
with a value containing new lines.strsplit
function with the newline character '\n'
to split the string into a list of substrings.str <- 'Hello\nWorld\n'
substrings <- strsplit(str, '\n', fixed = TRUE)[[1]]
for (sub in substrings) {
print(sub)
}
Hello World
In this tutorial, we learned How to Split a String by New Line in R language with well detailed examples.