Here is another way:

aggregate(.~ A + B, FUN = length, x)


On Tue, Apr 3, 2012 at 3:26 PM, Steven Raemaekers <s.raemaek...@sig.eu>wrote:

> Hi,
>
> I have a query which I would like to translate into R, but I do not know
> how to do it in an easy way.
> Assume a data frame has columns A, B and C:
>
> A       B       C
> 1       1       3
> 1       1       4
> 1       1       5
> 1       2       6
> 1       2       7
> 1       3       8
>
> The query is as follows:
>
> select A, B, count(*)
> from data.frame
> group by A, B
> order by count(*) desc
>
> How do I translate this into R statements in such way that the result is a
> data frame structured as follows:
>
> A       B       count(*)
> 1       1       3
> 1       2       2
> 1       3       1
>
> Thanks,
>
> Steven
> ______________________________________________
> R-help@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.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

        [[alternative HTML version deleted]]

______________________________________________
R-help@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.

Reply via email to