[R] [Fwd: formatting using the write statement]
markleeds at verizon.net
markleeds at verizon.net
Tue Jul 4 17:03:14 CEST 2006
>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 )
>
>}
>}
More information about the R-help
mailing list