[R] Applying do.call to a data.frame using function arguments
William Dunlap
wdunlap at tibco.com
Wed Aug 26 22:34:41 CEST 2009
> -----Original Message-----
> From: r-help-bounces at r-project.org
> [mailto:r-help-bounces at r-project.org] On Behalf Of miller_2555
> Sent: Wednesday, August 26, 2009 9:32 AM
> To: r-help at r-project.org
> Subject: Re: [R] Applying do.call to a data.frame using
> function arguments
>
>
>
> miller_2555 wrote:
> >
> > I'm trying to convert a data.frame to a series of strings
> (row-wise).
> > There was a very good discussion awhile back (2002)
> entitled "[R] string
> > concatenate across rows of a matrix??" where Tony Plate
> recommended the
> > following two alternatives (x2 is an R object of type data
> frame -- a
> > matrix also works for solution #1):
> > 1) apply(format(x2), 1, paste, collapse=" ");
> > 2) do.call("paste",x2)
> >
>
> Nevermind. Stupid question. The solution is:
> do.call("paste",c(x2,sep='","'));
This works most of the time but will fail if your
data.frame has a column called "sep" or "collapse"
(the named arguments to paste()). Changing
x2 to unname(x2) or unname(as.list(x2)) makes it
more bulletproof.
Bill Dunlap
TIBCO Software Inc - Spotfire Division
wdunlap tibco.com
>
> Hope this helps somebody.
> --
> View this message in context:
> http://www.nabble.com/Applying-do.call-to-a-data.frame-using-f
> unction-arguments-tp25151441p25151445.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
More information about the R-help
mailing list