[R] formated output

Duncan Murdoch dmurdoch at pair.com
Sun Mar 21 22:38:25 CET 2004


On Sun, 21 Mar 2004 21:47:33 +0100, you wrote:

>Hi all;
>I need to create ASCII files as output from R and I'm using sink(), cat(), 
>and paste() for this.
>My problem is that the ASCII files hace several columns, and I would like to 
>know if intermediate columns (the second one for example) could be alineated 
>to the right. My values are integer ranging from 1 to 1000.

You want to look at the formatC function together with paste to build
up the lines you want.  For example,

> x <- sample(200,5)
> y <- sample(200,5)
> cat(paste(formatC(x, width=5), formatC(y, width=5)), sep='\n')
   84    36
  159    64
   55    78
   59    51
  132   107

Duncan Murdoch




More information about the R-help mailing list