Re: [R] paste: multiple collapse arguments?

From: Christos Hatzis <christos_at_nuverabio.com>
Date: Mon, 25 Aug 2008 22:20:44 -0400

Try this:

> paste(paste(x, c(" ","\n"), sep=""), collapse="")
[1] "1 2\n3 4\n5 6\n"

-Christos Hatzis

> -----Original Message-----
> From: r-help-bounces_at_r-project.org
> [mailto:r-help-bounces_at_r-project.org] On Behalf Of remko duursma
> Sent: Monday, August 25, 2008 7:37 PM
> To: r-help_at_r-project.org
> Subject: [R] paste: multiple collapse arguments?
>
>
> Dear R-helpers,
>
> I have a numeric vector, like:
>
> x <- c(1,2,3,4,5,6)
>
> I make this into a string for output to a text file, separated by \n:
>
> paste(x, collapse="\n")
>
> Is there a way to alternate the collapse argument? So between
> the first two elements of x, I want to separate by " ", then
> by "\n", and so forth.
> The result should then look like:
> "1 2\n3 4\n5 6"
>
> (This way I get 2 elements of x on each line using
> writeLines, instead of one or all).
> I could do this in some ugly loop, but surely there is a better way?
>
> thanks,
> Remko
>
>
>
>
>
>
> _________________________________________________________________
> Get thousands of games on your PC, your mobile phone, and the
> web with Windows..
>
> [[alternative HTML version deleted]]
>
>



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. Received on Tue 26 Aug 2008 - 04:32:47 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 26 Aug 2008 - 05:33:58 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive