Re: [R] Percentages for categorical data by group

From: Economics Guy <economics.guy_at_gmail.com>
Date: Fri, 23 May 2008 13:31:45 -0400

Thanks Michael that works!

Now I am having a problem getting the results into a format I can use.

prop.table generates a contingency table that I tried to turn into a data frame I could graph from with as.data.frame() however the results are not a true data.frame. The rows have commas between some of the elements and trying to look at a column results in the original contingency table being displayed.

This is what I have:

pop <- matrix(1:100000)
groupIDs <- sample(pop,500)
groupVar <- sample(groupIDs,23000,replace=TRUE) responseVar <- sample(1:5,23000,replace=TRUE)

example.data <- data.frame(groupVar,responseVar)

data.table <-
tapply(example.data$responseVar,example.data$groupVar,function(x){prop.table(table(x))})

example.data.frame <- as.data.frame(data.table)

But the example.data.frame object is not a true data frame, and I am not sure how to get it into a format I can graph.

On Fri, May 23, 2008 at 11:33 AM, Michael Conklin < michael.conklin_at_markettools.com> wrote:

> tapply(example.data$responseVar,example.data$groupVar,function(x){prop.t
> able(table(x))})
>
> Michael Conklin
>
> Chief Methodologist - Advanced Analytics
>
>
>
>

        [[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. Received on Fri 23 May 2008 - 18:17:17 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 - 18: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