Skip to content
Prev 177068 / 398503 Next

Controlling widths in write.fwf()

Thanks Brendan. 
write.table() doesn't seem to do it for me. The problem is that my data
is not formatted as well as you show in the example. There are numbers
and strings of varying sizes and write.table() misses the format. 

Aparna 

-----Original Message-----
From: Brendan Morse [mailto:morse.brendan at gmail.com] 
Sent: Tuesday, April 14, 2009 5:35 PM
To: Vemuri, Aparna
Cc: r-help at r-project.org
Subject: Re: [R] Controlling widths in write.fwf()

Hi Aparna, you could always use the write.table function and set  
sep="". This will put all of your data into a sort of "fixed-width"  
column depending on what you specify to separate the values. See basic  
example below:

x<-matrix(nrow=2, ncol=2, c(1,2,3,4))
write.table(x, "/Users/morse07/Desktop/x.txt", sep="",  
col.names=FALSE, row.names=FALSE)

Note that any spaces you insert between the "" after the sep command  
will insert 1 fixed-width column per space in your file.

Hope that helps,
Brendan
On Apr 14, 2009, at 7:28 PM, Vemuri, Aparna wrote:

            
http://www.R-project.org/posting-guide.html