From ripley at stats.ox.ac.uk  Thu Mar  6 18:04:03 2003
From: ripley at stats.ox.ac.uk (ripley@stats.ox.ac.uk)
Date: Thu Mar  6 19:04:13 2003
Subject: [Rd] write.table row.names and col.names (PR#2610)
In-Reply-To: <200303061741.h26Hfcn9029108@pubhealth.ku.dk>
Message-ID: <Pine.LNX.4.44.0303061753280.1350-100000@gannet.stats>

There was no need to send this twice: this is also PR#2611.

This _is_ the documented behaviour, and it _is_ also discussed in the R
Import/Export Manual.  ?write.table says:

     Normally there is no column name for a column of row names.  If
     `col.names=NA' a blank column name is added.  This can be used to
     write CSV files for input to spreadsheets.

Please _only_ send messages once and _only_ after reading at least the 
help page.  Your lack of reading is not a bug in R.

On Thu, 6 Mar 2003 w.huber@dkfz.de wrote:

> Full_Name: Wolfgang Huber
> Version: 1.6.2
> OS: DEC OSF, Win, Linux
> Submission from: (NULL) (155.52.45.139)
> 
> 
> When data.frames are written to a file using write.table and with row.names and
> col.names, then the colnames are displaced by 1 with respect to column content.
> Example:
> 
> 
> > x = data.frame(
> >   obscht=c("chriesi", "bire"),
> >     gmues=c("chrut","hoerdoepfl"))
> > rownames(x) = c("huet", "morn")
> > write.table(x, file="test.txt", sep="\t", quote=F)
> 
> The table x now looks like:
> > x
>       obscht      gmues
> huet chriesi      chrut
> morn    bire hoerdoepfl
> 
> but the file is as follows, and the column names will be confused when reading
> this file e.g. from Excel.
> 
> obscht	gmues
> huet	chriesi	chrut
> morn	bire	hoerdoepfl

The separators are not visible there.  Try

>  write.table(x, file="", sep=",", quote=F)
obscht,gmues
huet,chriesi,chrut
morn,bire,hoerdoepfl

to see what is really going on.

-- 
Brian D. Ripley,                  ripley@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595


[Rd] write.table row.names and col.names (PR#2610)
ripley@stats.ox.ac.uk