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 ?
Thanks in advance
Heinz Tuechler
how to print a data.frame without row.names
6 messages · Heinz Tuechler, Romain Francois, Martin Maechler +1 more
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 ~~~~~~ ~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~
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', 'bbbb', '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 bbbb
3 2004-04-12 Ostern 110 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 bbbb
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 ~~~~~~ ~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~
"Heinz" == Heinz Tuechler <tuechler at gmx.at>
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")
Martin Maechler <maechler at stat.math.ethz.ch> writes:
"Heinz" == Heinz Tuechler <tuechler at gmx.at>
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 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907
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 <maechler at stat.math.ethz.ch> writes:
"Heinz" == Heinz Tuechler <tuechler at gmx.at>
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
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907