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:> xobscht 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
Dirk Eddelbuettel
2003-Mar-06 18:46 UTC
[Rd] write.table row.names and col.names (PR#2610)
On Thu, Mar 06, 2003 at 06:41:38PM +0100, w.huber@dkfz.de wrote:> 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 hoerdoepflAFAIK that is a feature. Look at the example(write.table), it does precisely this and gets data back and forth to Excel. Dirk -- Prediction is very difficult, especially about the future. -- Niels Bohr
On Thu, 6 Mar 2003, Dirk Eddelbuettel wrote:> AFAIK that is a feature. Look at the example(write.table), it does precisely > this and gets data back and forth to Excel. >Hi Dirk, thanks! Seems I should have better read the documentation, sorry for wasting your time. I had never been sure whether the default behavior of write.table was a bug or a feature and as this topic had come up today again, someone had encouraged me to submit a bug report :) Best regards Wolfgang
ripley@stats.ox.ac.uk
2003-Mar-06 19:04 UTC
[Rd] write.table row.names and col.names (PR#2610)
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 hoerdoepflThe 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
Warnes, Gregory R
2003-Mar-06 21:07 UTC
[Rd] write.table row.names and col.names (PR#2610)
>From ?write.table: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. -Greg> -----Original Message----- > From: w.huber@dkfz.de [mailto:w.huber@dkfz.de] > Sent: Thursday, March 06, 2003 12:42 PM > To: r-devel@stat.math.ethz.ch > Cc: R-bugs@biostat.ku.dk > Subject: [Rd] write.table row.names and col.names (PR#2610) > > > 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 > > ______________________________________________ > R-devel@stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-devel >LEGAL NOTICE\ Unless expressly stated otherwise, this message is... [[dropped]]