[R] Cross-tabulation Question
Gabor Grothendieck
ggrothendieck at gmail.com
Mon Sep 29 16:26:30 CEST 2008
Try this:
> with(unique(x), table(V2, V3))
V3
V2 Apple Cake
One 2 1
On Mon, Sep 29, 2008 at 4:54 AM, Shubha Vishwanath Karanth
<shubhak at ambaresearch.com> wrote:
> Hi R,
>
>
>
> This is a cross tabulation question. Suppose that,
>
>
>
>> d=read.table("clipboard",header=F)
>
>
>
>> d
>
> V1 V2 V3
>
> A One Apple
>
> A One Cake
>
> A One Cake
>
> B One Apple
>
> B One Apple
>
> B One Apple
>
>
>
>> table(d$V2,d$V3)
>
>
>
> Apple Cake
>
> One 4 2
>
>
>
>
>
> But, I don't want the count to be like the above. Here, it is counting
> the number of rows in that particular category. What I need is in each
> category, the count of unique V1's. So, my output should look like,
>
>
>
> Apple Cake
>
> One 2 1
>
>
>
>
>
> Any ideas please...
>
>
>
> Thanks, Shubha
>
>
>
> This e-mail may contain confidential and/or privileged i...{{dropped:13}}
>
> ______________________________________________
> R-help at 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.
>
More information about the R-help
mailing list