Re: [R] Percentages for categorical data by group

From: Michael Conklin <michael.conklin_at_markettools.com>
Date: Fri, 23 May 2008 15:59:03 -0500

 prop.table(table(factor(x,levels=1:5)))

Michael Conklin

Chief Methodologist - Advanced Analytics  

MarketTools, Inc.

6465 Wayzata Blvd. Suite 170

Minneapolis, MN 55426

Tel: 952.417.4719 | Mobile:612.201.8978

Michael.Conklin_at_markettools.com  

MarketTools(r) http://www.markettools.com  

This e-mail and any attachments may contain privileged, confidential or proprietary information. If you are not the intended recipient, be aware that any review, copying, or distribution of this e-mail or any attachment is strictly prohibited. If you have received this e-mail in error, please return it to the sender immediately, and permanently delete the original and any copies from your system. Thank you for your cooperation.  

-----Original Message-----
From: r-help-bounces_at_r-project.org [mailto:r-help-bounces_at_r-project.org] On Behalf Of Economics Guy
Sent: Friday, May 23, 2008 1:36 PM
To: r-help_at_stat.math.ethz.ch
Subject: Re: [R] Percentages for categorical data by group

I appreciate all the help. The trouble is that in my real data set each group does not always have an observation that choose each response. This
results in some of the "rows" returned from prop.table() to be shorter than
others so I get:

Warning message:
In function (..., deparse.level = 1) :
  number of columns of result is not a multiple of vector length (arg 8)

Is there a way to tell rbind() or do.call() to treat missing values as zero
or make prop.table() include the zero proportions?

On Fri, May 23, 2008 at 1:59 PM, Phil Spector <spector_at_stat.berkeley.edu>
wrote:

> EG -
> Thanks for the reproducible example!
>
> When I run your code, and check the class of the result from
tapply(), I
> see that it is an
> "array", and using dim(), I see it's an array
> of length 500. How big is each element?
>
> table(sapply(res,length))
>>
>
> 5
> 500
>
> So each piece is the same length. That means we could
> make a 500x5 matrix as follows:
>
> do.call(rbind,res)
> - Phil Spector
> Statistical Computing Facility
> Department of Statistics
> UC Berkeley
> spector_at_stat.berkeley.edu
>
>
>
>
>
>
>

        [[alternative HTML version deleted]]



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.

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. Received on Fri 23 May 2008 - 21:05:45 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Fri 23 May 2008 - 22:30:43 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive