[R] How to remove extra spaces introduced (?) by write.table

Valtteri Wirta valtteri at biotech.kth.se
Wed Dec 10 12:31:51 CET 2003


Dear Group,

My question relates to the write.table function.

I have created a data.frame containing both "character" and "numeric" columns.
When I use the write.table function to write this table into a text file 
spaces are added into the "numeric" columns so that the number of digits in 
each column is the same. This extra space is added before the actual number.

I write the table using the following command:
write.table(out.obj, sep="\t", file="test.txt", row.names=FALSE, na="NaN", 
quote=FALSE)
where out.obj is the data.frame

A simplified example with three columns
Sample1\t10\t10
Sample2\t*1\t*1

The * denotes the extra space, \t is the tab used as separator
(a real example can be found at 
http://biobase.biotech.kth.se/~valtteri/test.txt)

I need to remove these spaces as they are not compatible with the 
down-stream application. I'd prefer not to remove these manually using for 
example MS-Word as the number of files generated is fairly large.

I verified the modes of the problematic columns and they are, as expected, 
"numeric".

My question is how to remove these extra spaces?
SUB did not work (good for "character" vectors).


I'm using R.1.8.0 running under Windows XP
A saved copy of the data.frame can be found at 
http://biobase.biotech.kth.se/~valtteri/test.RData
(saved with ascii=TRUE)


All help is appreciated.

Thanks,

Valtteri





Contact information:

Valtteri Wirta
Department of Biotechnology, KTH
AlbaNova University Center
S - 10691 Stockholm, Sweden

Visiting address: Roslagstullsbacken 21, B3
Phone: +46 8 5537 8344(office)
Phone: +46 733 386 341 (gsm)
Fax: +46 8 5537 8481
Email: valtteri at biotech.kth.se
Web: www.biotech.kth.se/molbio
MSN messenger: valzu at hotmail.com




More information about the R-help mailing list