Re: [R] how to print a data.frame without row.names
Le 02.08.2005 15:45, Heinz Tuechler a écrit : Dear All, is there a simple way to print a data.frame without its row.names? example: datum - as.Date(c(2004-01-01, 2004-01-06, 2004-04-12)) content - c('Neujahr', 'Hl 3 K.', 'Ostern') df1 - data.frame(datum, content) print(df1) datum content 1 2004-01-01 Neujahr 2 2004-01-06 Hl 3 K. 3 2004-04-12 Ostern Can I get this table without 1, 2, 3 ? See write.table and its row.names argument R write.table(df1, row.names=FALSE) Romain -- visit the R Graph Gallery : http://addictedtor.free.fr/graphiques ~ ~~ Romain FRANCOIS - http://addictedtor.free.fr ~~ Etudiant ISUP - CS3 - Industrie et Services ~~http://www.isup.cicrp.jussieu.fr/ ~~ Stagiaire INRIA Futurs - Equipe SELECT ~~ http://www.inria.fr/recherche/equipes/select.fr.html~~ ~ __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] how to print a data.frame without row.names
At 16:05 02.08.2005 +0200, Romain Francois wrote: Le 02.08.2005 15:45, Heinz Tuechler a écrit : Dear All, is there a simple way to print a data.frame without its row.names? example: datum - as.Date(c(2004-01-01, 2004-01-06, 2004-04-12)) content - c('Neujahr', 'Hl 3 K.', 'Ostern') df1 - data.frame(datum, content) print(df1) datum content 1 2004-01-01 Neujahr 2 2004-01-06 Hl 3 K. 3 2004-04-12 Ostern Can I get this table without 1, 2, 3 ? See write.table and its row.names argument R write.table(df1, row.names=FALSE) Romain write.table(df1, row.names=FALSE, quote=FALSE) datum content 2004-01-01 Neujahr 2004-01-06 Hl 3 K. 2004-04-12 Ostern I tried this, but then the column headers and column contents are not aligned. If you expand the example, you see clearly the difference. datum - as.Date(c(2004-01-01, 2004-01-06, 2004-04-12)) content - c('Neujahr', 'Hl 3 K.', 'Ostern') number - c(1, 6, 110) string - c('a', '', 'c') df1 - data.frame(datum, content, number, string) print(df1) datum content number string 1 2004-01-01 Neujahr 1 a 2 2004-01-06 Hl 3 K. 6 3 2004-04-12 Ostern110 c write.table(df1, row.names=FALSE, quote=FALSE) datum content number string 2004-01-01 Neujahr 1 a 2004-01-06 Hl 3 K. 6 2004-04-12 Ostern 110 c Maybe I missed a function like print.xtable with type=ascii. It seems that it has to be done with cat. Thank you Heinz -- visit the R Graph Gallery : http://addictedtor.free.fr/graphiques ~ ~~ Romain FRANCOIS - http://addictedtor.free.fr ~~ Etudiant ISUP - CS3 - Industrie et Services ~~http://www.isup.cicrp.jussieu.fr/ ~~ Stagiaire INRIA Futurs - Equipe SELECT ~~ http://www.inria.fr/recherche/equipes/select.fr.html~~ ~ __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] how to print a data.frame without row.names
Heinz == Heinz Tuechler [EMAIL PROTECTED] on Tue, 02 Aug 2005 17:46:07 +0200 writes: ... Heinz I tried this, but then the column headers and column Heinz contents are not aligned. Use the tabulator if you need them aligned : write.table(USArrests, row.names = FALSE, sep = \t) __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] how to print a data.frame without row.names
Martin Maechler [EMAIL PROTECTED] writes: Heinz == Heinz Tuechler [EMAIL PROTECTED] on Tue, 02 Aug 2005 17:46:07 +0200 writes: ... Heinz I tried this, but then the column headers and column Heinz contents are not aligned. Use the tabulator if you need them aligned : write.table(USArrests, row.names = FALSE, sep = \t) Unless a column or a header is 8 chars or wider (and UrbanPop is!). This seems to do it: x - as.matrix(format(USArrests)) rownames(x) - rep(, nrow(x)) print(x, quote=FALSE, right=TRUE) -- O__ Peter Dalgaard Øster Farimagsgade 5, Entr.B c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~ - ([EMAIL PROTECTED]) FAX: (+45) 35327907 __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] how to print a data.frame without row.names
Thanks to all of you for your help. As far as I see, the solution of Peter Dalgaard works exactly as I want. All other solutions have limitations. Heinz At 19:19 02.08.2005 +0200, Peter Dalgaard wrote: Martin Maechler [EMAIL PROTECTED] writes: Heinz == Heinz Tuechler [EMAIL PROTECTED] on Tue, 02 Aug 2005 17:46:07 +0200 writes: ... Heinz I tried this, but then the column headers and column Heinz contents are not aligned. Use the tabulator if you need them aligned : write.table(USArrests, row.names = FALSE, sep = \t) Unless a column or a header is 8 chars or wider (and UrbanPop is!). This seems to do it: x - as.matrix(format(USArrests)) rownames(x) - rep(, nrow(x)) print(x, quote=FALSE, right=TRUE) -- O__ Peter Dalgaard Øster Farimagsgade 5, Entr.B c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~ - ([EMAIL PROTECTED]) FAX: (+45) 35327907 __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html