Is there a way to paste together the elements of a vector in R without using a loop?

Solution 1:

You just need to use the collapse argument:

paste(x,collapse="")

Solution 2:

Just adding a tidyverse way to provide an alternative to using paste():

library(glue)
x <- c("a", " ", "b")
glue_collapse(x)
#> a b

Created on 2020-10-31 by the reprex package (v0.3.0)