Skip to content
Prev 74774 / 398502 Next

how to print a data.frame without row.names

At 16:05 02.08.2005 +0200, Romain Francois wrote:
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