[R] Combining the components of a character vector

Ray Brownrigg ray at mcs.vuw.ac.nz
Thu Apr 3 22:27:20 CEST 2003


>    Suppose I have a character vector.
> 
> x <- c("Bob", "loves", "Sally")
> 
> I want to combine it into a single string:  "Bob loves Sally" .
> paste(x) yields:
> paste(x)
> [1] "Bob"   "loves" "Sally"
> 
> Is there a more natural (no loop) way to do this in R?
> 
RTFM:
> paste(x, collapse=" ")
[1] "Bob loves Sally"

Ray



More information about the R-help mailing list