How to concatenate two strings in R
In this tutorial, we are going to learn about concatenating two strings in the r programming language.
Using the paste() method
The paste()
method takes the two strings as a first argument, second argument, and concatenate it into a single string.
Here is an example:
x <- "hello"
y <- "world"
paste(x, y)
Output:
[1] "hello world"
You can also concatenate two strings by using a separator like this:
x <- "hello"
y <- "world"
paste(x, y, sep= "-")
Output:
[1] "hello-world"
Similarly, you can also use the stri_paste()
function from the stringi
package like this.
name = c('josh', 'king')
stri_paste(letters, collapse= "")