Skip to content
Back to formatted view

Raw Message

Message-ID: <Pine.A41.4.44.0304040648180.199144-100000@homer04.u.washington.edu>
Date: 2003-04-04T14:51:02Z
From: Thomas Lumley
Subject: Combining the components of a character vector
In-Reply-To: <200304031227.h33CR9Vb004057@thorin.ci.tuwien.ac.at>

> On Thursday 03 April 2003 01:54, John Miyamoto wrote:

<snippage>

> > 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?

I might also take this opportunity to note that if paste() didn't have the
collapse=  argument there would still be more elegant way to write the
loop

   do.call("paste",as.list(x))

creates a call to paste() whose arguments are the elements of x.


	-thomas