[R] Printing data.frame data: alternatives to print?

Matthew Pettis matthew.pettis at gmail.com
Fri Oct 29 15:53:55 CEST 2010


Hi,

I have a data frame with two factors (well, more, but 2 for simple
consideration), and I want to display the different combinations of
the them that actually occur in the data.  In reality, there are too
many of them to do to do a 'table' call and have one col vertical and
one col horizontal (I don't want any of the factors listed
horizontally).  Before I try to write a function to do this for me, I
was wondering if there were alternate printing styles for data that
already exist, and if someone could direct me to them?  Inclded is a
sample code and 2 possibilities (others welcome for consideration) of
how I want to display some data.

Thanks,
Matt

-----

df <- data.frame(
    f1=rep(c("Maj I", "Maj II", "Maj III"), each=3),
    f2=c("Minor A", "Minor A", "Minor A", "Minor A", "Minor B", "Minor
B", "Minor B", "Minor C", "Minor C")
)

-----

What I want printed is something like:

-------------------
      f1         f2
Maj I       Minor A

Maj II      Minor A
            Minor B

Maj III     Minor B
            Minor C
-------------------

or

-------------------
      f1         f2
Maj I       Minor A

Maj II      Minor A
Maj II      Minor B

Maj III     Minor B
Maj III     Minor C



More information about the R-help mailing list