[R] plyr and table question

baptiste auguie ba208 at exeter.ac.uk
Fri Apr 3 15:57:38 CEST 2009


of course!

Thanks,

baptiste

On 3 Apr 2009, at 14:48, hadley wickham wrote:

> 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/

_____________________________

Baptiste Auguié

School of Physics
University of Exeter
Stocker Road,
Exeter, Devon,
EX4 4QL, UK

Phone: +44 1392 264187

http://newton.ex.ac.uk/research/emag




More information about the R-help mailing list