Message-ID: <Pine.A41.4.44.0304021552520.19986-100000@mead5.u.washington.edu>
Date: 2003-04-02T23:54:14Z
From: John Miyamoto
Subject: Combining the components of a character vector
Dear Help,
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"
The following function combines the character vector into a string in the
way that I want, but it seems somewhat inelegant.
paste.vector <- function(x, ...) {
output <- NULL
for (i in 1:length(x)) output <- paste(output, x[i], ...)
output } #end of function definition
paste.vector(x)
[1] " Bob loves Sally"
Is there a more natural (no loop) way to do this in R?
John Miyamoto
--------------------------------------------------------------------
John Miyamoto, Dept. of Psychology, Box 351525
University of Washington, Seattle, WA 98195-1525
Phone 206-543-0805, Fax 206-685-3157, Email jmiyamot at u.washington.edu
Homepage http://faculty.washington.edu/jmiyamot/
--------------------------------------------------------------------