[R] Printing data.frame data: alternatives to print?
Jan van der Laan
rhelp at eoos.dds.nl
Fri Oct 29 16:08:52 CEST 2010
Matt,
Below are three (of the probably many more) possible ways of doing this:
aggregate(1:nrow(df), df, length)
ftable(1 ~ f1 + f2, data=df)
library(plyr)
ddply(df, .(f1,f2), nrow)
Regards,
Jan
On 29-10-2010 15:53, Matthew Pettis wrote:
> 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
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help
mailing list