Daren Tan
2008-Oct-31 01:35 UTC
[R] Proper way to write data frame with column and row names
I need to write a data frame along with its column and row names to a text file. However, the first row in the text file is always short of one element. I have tried setting different parameters to write.table but that didn't help.> mA B C 1 2 D 3 4 Using write.table(m, "table.xls", sep="\t", col.names=T, row.names=T) gives A B C 1 2 D 3 4
Simon Blomberg
2008-Oct-31 01:58 UTC
[R] Proper way to write data frame with column and row names
Try setting row.names=FALSE in the call to write.table. If you really need those row names, create a variable containing the row names in the data frame. Then use write.table with row.names=FALSE. HTH, Simon. On Fri, 2008-10-31 at 01:35 +0000, Daren Tan wrote:> I need to write a data frame along with its column and row names to a text file. However, the first row in the text file is always short of one element. I have tried setting different parameters to write.table but that didn't help. > > > m > A B > C 1 2 > D 3 4 > > Using write.table(m, "table.xls", sep="\t", col.names=T, row.names=T) gives > > A B > C 1 2 > D 3 4 > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.-- Simon Blomberg, BSc (Hons), PhD, MAppStat. Lecturer and Consultant Statistician Faculty of Biological and Chemical Sciences The University of Queensland St. Lucia Queensland 4072 Australia Room 320 Goddard Building (8) T: +61 7 3365 2506 http://www.uq.edu.au/~uqsblomb email: S.Blomberg1_at_uq.edu.au Policies: 1. I will NOT analyse your data for you. 2. Your deadline is your problem. The combination of some data and an aching desire for an answer does not ensure that a reasonable answer can be extracted from a given body of data. - John Tukey.