by Sai gowtham

How to concatenate vector of characters/strings in R

To concatenate the vector of characters/strings into a single string, we can use the paste() function by passing collapse= '' as the second argument in R programming language.

Here is an example that concatenates the following vector of characters to a single string.

letters = c('g', 'a', 'p')
paste(letters,  collapse= '')

Output:

[1] "gap"

Similarly, you also use the following solution to concatenate it.

letters = c('g', 'a', 'p')
do.call(paste, c(as.list(letters), sep = ""))

or you can use the stri_paste() function from the stringi package like this.

letters = c('g', 'a', 'p')
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 - The Complete Guide (w/ Router, Vuex, Composition API)
Vue - The Complete Guide (w/ Router, Vuex, Composition API)
130,921 students enrolled
48.5 hours of video content
View Course