Concatenate a vector of strings/character

Nick picture Nick · Jan 20, 2010 · Viewed 304.3k times · Source

If I have a vector of type character, how can I concatenate the values into string? Here's how I would do it with paste():

sdata = c('a', 'b', 'c')
paste(sdata[1], sdata[2], sdata[3], sep ='')

yielding "abc".

But of course, that only works if I know the length of sdata ahead of time.

Answer

Matt Turner picture Matt Turner · Jan 20, 2010

Try using an empty collapse argument within the paste function:

paste(sdata, collapse = '')

Thanks to http://twitter.com/onelinetips/status/7491806343