[R] write merged data frame to a file

Philipp Pagel p.pagel at wzw.tum.de
Mon Jul 18 16:32:18 CEST 2011

On Mon, Jul 18, 2011 at 04:00:29PM +0200, Andrea Franceschini wrote:
> I use version 13 of R in OSX (downloaded and installed less than 1 year ago).

Probably 2.13 ...

[...] code omitted

> The first lines are OK (i.e. 14 columns, like the dataframe), while at
> a certain point I get lines with only 3 columns !!!
> The bad lines that contain only 3 columns have the name and the
> description of the gene (i.e. the content of the file that I merged
> with).
> Besides, these strange lines also get repeated (see the bottom).

I havent't carefully analyzed your code so I may be wrong but my guess for
all "weird behaviour of gene related data.frames" problems is this:

Gene descriptions love to contain things like "Foo 5' obfuscation
factor".  Note the "'" in the description which read.table will
happily interpret as a quotation mark and eat lots of rows until it
happens to encouter a closing counterpart. This leads to all kinds of
funny results. So I bet your problem is not in write.table but in
reading the data. Have a closer look at your data frame: are you
really getting the expected number of observations in the merged
data.frame? Are the rows in question really ok in the data frame? If
my guess is correct you should be able to fix your problem by
including quote="" in both your read.table commands.

If it doesn't, also try comment.char="" - another popular source of


Dr. Philipp Pagel
Lehrstuhl für Genomorientierte Bioinformatik
Technische Universität München
Wissenschaftszentrum Weihenstephan
85350 Freising, Germany

More information about the R-help mailing list