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



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

say there's vector x:

x <- c("a", " ", "b")

and want turn single string "a b". there way without loop? know loop this:

y <- "" (i in 1:3){ paste(y, x[i], sep = "") } > y [1] "a b"

but need on many, many iterations, , having loop on , replace original new each time become time consuming. want able this:

x <- paste(x)

as if paste() smartly split elements of vector itself, know can't. there function, or more creative way utilize paste(), can accomplish efficiently?

you need utilize collapse argument:

paste(x,collapse="")

r paste memory-efficient

Comments

Popular posts from this blog

iphone - Dismissing a UIAlertView -

c# - Can ProtoBuf-Net deserialize to a flat class? -

javascript - Change element in each JQuery tab to dynamically generated colors -