As you can see there are lots of ways to get this done! But in vanilla R:
test = data.frame(A=rep(1,6),B=c(1,1,1,2,2,3),C=1:6)
with(test,aggregate(C,list(A,B),length))
does what you've asked, I think.
On Tue, Apr 3, 2012 at 1:26 PM, Steven Raemaekers <s.raemaekers@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.
>



-- 
Drew Tyre

School of Natural Resources
University of Nebraska-Lincoln
416 Hardin Hall, East Campus
3310 Holdrege Street
Lincoln, NE 68583-0974

phone: +1 402 472 4054
fax: +1 402 472 2946
email: atyre2@unl.edu
http://snr.unl.edu/tyre
http://aminpractice.blogspot.com
http://www.flickr.com/photos/atiretoo

	[[alternative HTML version deleted]]

