[Rd] write.table row.names and col.names (PR#2610)
ripley at stats.ox.ac.uk
ripley at stats.ox.ac.uk
Thu Mar 6 18:04:03 MET 2003
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 at 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 at 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
More information about the R-devel
mailing list