On Thu, Feb 3, 2011 at 10:05 PM, Peter Ehlers <ehl...@ucalgary.ca> wrote:
> On 2011-02-03 14:09, Dennis Murphy wrote:
>>
>> Hi:
>>
>> This also works, except that the result is of class 'table':
>>
>> xtabs(COUNTS ~ USER_ID + SITE, data = RAW)
>>        SITE
>> USER_ID SITE1 SITE2 SITE3
>>       1    10    13    22
>>       2    10    12    12
>>       3    13    44     0
>>       4     0     0    99
>>
>> If you need a data frame, then the earlier responses apply.
>
> Agreed. But just for fun, since this is R:
>
>  z <- xtabs(COUNTS ~ USER_ID + SITE, data = RAW)
>  d <- as.data.frame(unclass(z))
>
> That'll lose the USER_ID variable; if that's needed:
>
>  d <- as.data.frame(cbind(USER_ID=row.names(z), unclass(z)))
>

Try this:

cbind( dimnames( z )[ 1 ], as.data.frame( z[ ] ) )



-- 
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com

______________________________________________
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