by Sai gowtham

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= "")

Top Udemy Courses

JavaScript - The Complete Guide 2020 (Beginner + Advanced)
JavaScript - The Complete Guide 2020 (Beginner + Advanced)
45,614 students enrolled
52 hours of video content
View Course
React - The Complete Guide (incl Hooks, React Router, Redux)
React - The Complete Guide (incl Hooks, React Router, Redux)
284,472 students enrolled
40 hours of video content
View Course
Vue JS 2 - The Complete Guide (incl. Vue Router & Vuex)
Vue JS 2 - The Complete Guide (incl. Vue Router & Vuex)
130,921 students enrolled
21 hours of video content
View Course