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