[R] plyr and table question

hadley wickham h.wickham at gmail.com
Fri Apr 3 15:48:52 CEST 2009


On Fri, Apr 3, 2009 at 8:43 AM, baptiste auguie <ba208 at exeter.ac.uk> wrote:
> That makes sense, so I can do something like,
>
> count <- function(x){
>        as.integer(unclass(table(x)))
> }
>
> count(d$user_id)
>
> ddply(d, .(user_id), transform, count = count(user_id))
>
>>  user_id  website time count
>> 1      20   google  930     2
>> 2      20 facebook 1000     2
>> 3      21    yahoo  935     1
>> 4      25 facebook 1015     1
>> 5      61   google  940     1
>
> Have I missed a built-in function to obtain this result?

ddply(d, .(user_id), transform, count = nrow)

?

Hadley

-- 
http://had.co.nz/




More information about the R-help mailing list