[R] print data frames without row names (within a list)

Daniel Ezra Johnson danielezrajohnson at gmail.com
Sun Aug 10 14:00:06 CEST 2008

This should be an easy one, but I could not find the answer in the
obvious places.

one <- data.frame(a=c(1,2,3),b=c("x","y","z"))
two <- data.frame(a=c(4,5,6),b=c("q","r","s"))

> print(one)
 a b
1 1 x
2 2 y
3 3 z

> print(one,row.names=F)
 a b
 1 x
 2 y
 3 z

So far, so good, but how do I do this if the data frames are bound into a list?

> three <- list(one,two)
> print(three,row.names=F)  #same as print(three,row.names=T)

 a b
1 1 x
2 2 y
3 3 z

 a b
1 4 q
2 5 r
3 6 s

Is there any way to stop the row (or column) names from printing in a
case like this?
I just thought of one way - change the default in print.data.frame()
and reload that function.

Surprisingly, that does not work. I have successfully changed the
behavior of:

> print(one)
> one

These now print without row names, but

> print(three)

continues to print the row names, even though

> class(three[[1]])

is "data.frame", so I'm not clear why it doesn't take the print
defaults from print.data.frame!

Any advice would be appreciated. I can live with the row names, but
there are cases where I want to suppress them within a list.


More information about the R-help mailing list