Re: [R] paste: multiple collapse arguments?

2008-08-26 Thread Henrique Dallazuanna
Try this also:

paste(apply(matrix(x, 2), 2, paste, collapse = ' '), collapse = \n)

On Mon, Aug 25, 2008 at 8:36 PM, remko duursma [EMAIL PROTECTED] wrote:

 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(R).

[[alternative HTML version deleted]]


 __
 R-help@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.





-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40 S 49° 16' 22 O

__
R-help@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.


[R] paste: multiple collapse arguments?

2008-08-25 Thread remko duursma

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@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.


Re: [R] paste: multiple collapse arguments?

2008-08-25 Thread jim holtman
Try this:

 x - c(1,2,3,4,5,6)
 paste(paste(x[seq(1, by=2, length=length(x)/2)], x[seq(2, by=2, 
 length=length(x)/2)]), collapse=\n)
[1] 1 2\n3 4\n5 6


On Mon, Aug 25, 2008 at 7:36 PM, remko duursma [EMAIL PROTECTED] wrote:

 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(R).

[[alternative HTML version deleted]]


 __
 R-help@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.





-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem that you are trying to solve?

__
R-help@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.


Re: [R] paste: multiple collapse arguments?

2008-08-25 Thread Moshe Olshansky
One possibility is:
y - rep( ,6)
y[6] - 
y[c(2,4)] - \n
res - paste(paste(x,y,sep=),collapse=)


--- On Tue, 26/8/08, remko duursma [EMAIL PROTECTED] wrote:

 From: remko duursma [EMAIL PROTECTED]
 Subject: [R] paste: multiple collapse arguments?
 To: r-help@r-project.org
 Received: Tuesday, 26 August, 2008, 9:36 AM
 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@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.

__
R-help@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.


Re: [R] paste: multiple collapse arguments?

2008-08-25 Thread Christos Hatzis
Try this:

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

-Christos Hatzis

 -Original Message-
 From: [EMAIL PROTECTED] 
 [mailto:[EMAIL PROTECTED] On Behalf Of remko duursma
 Sent: Monday, August 25, 2008 7:37 PM
 To: r-help@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@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.