[R] [Fwd: formatting using the write statement]

From: <markleeds_at_verizon.net>
Date: Wed 05 Jul 2006 - 01:03:14 EST

>I have a series of write statements because
>i am writing to a file
>where the characters strings are the column names of a dataframe
>and the numbers are the elements in a particular row.
>So, a file might look like
>
>AAA 2.1
>BB 3.1
>AHLZ 0.2
>
>and it would be named "rowname".mls.
>
>so, each time i get to a new row, i create a new file and write to it.
>
>the code is below and it works fine. my only question is
>there a way to tell the write statement that i want the data
>to be written in a fixed format ( same number of spaces
>betweewn character strings and numbers ) rather than written as it
>is above ? i tried sep = " ", instead of ncolumns butt hat
>just makde things worse. thanks.
>
>for (rownum in 1 (1:nrow(sortedForecastData)) {
>
>outfile=paste(forecsastfiledir,rownames(sortedForecastData[rownum],".mls",sep="")
>
>for colnum in (1:ncol(sortedForecastData) {
>
>if ( colnum == 1 ) {
>
>write(c(colnames(sortedForecastData[colnum],sortedForecastData[rownum,colnum],file=outfile,ncolumns=2,append=FALSE)
>
>} else {
>
>write(c(colnames(sortedForecastData)[colnum],sortedForecastData[rownum,colnum],file=outfile,ncolumns=2,append=TRUE )
>
>}
>}



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Wed Jul 05 02:29:40 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Wed 05 Jul 2006 - 04:15:02 EST.

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