Joining strings in R is quite an easy task. You can do it either with the help of “paste()” function or “string_c()” function from “stringR” package.
Consider an example:
We have the “fruit” vector, which comprises of names of fruits, and we would want to add the string “fruit” before the name of the fruit. Let’s go ahead and do that.
First, let’s have a glance at the “fruits” vector.
print(fruit)
[1] "apple" "orange"
let’s use the paste function:
paste("fruit",fruit)
[1] "fruit apple" "fruit orange"
perform the same task using “str_c()” function from “stringR” package.
str_c("fruit",fruit,sep="-")
[1]"fruit-apple" "fruit-orange"