On Wed, Jan 26, 2011 at 5:27 AM, Dennis Murphy <djmu...@gmail.com> wrote:
> Hi:
>
> Here are two more candidates, using the plyr and data.table packages:
>
> library(plyr)
> ddply(X, .(x, y), function(d) length(unique(d$z)))
>  x y V1
> 1 1 1  2
> 2 1 2  2
> 3 2 3  2
> 4 2 4  2
> 5 3 5  2
> 6 3 6  2
>
> The function counts the number of unique z values in each sub-data frame
> with the same x and y values. The argument d in the anonymous function is a
> data frame object.

Another approach is to use the much faster count function:

count(unique(X))

Hadley

-- 
Assistant Professor / Dobelman Family Junior Chair
Department of Statistics / Rice University
http://had.co.nz/

______________________________________________
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