Data comes from this RData dataset
Here is the script:
library(dplyr)
library(ggplot2)
load("brfss2013.RData")
test <- brfss2013 %>%
select(chcscncr,exract11) %>%
filter(chcscncr != "NA" , exract11 != "NA") %>%
group_by(exract11,chcscncr) %>%
summarise(count = n())
Which results in this table:
> head(test)
Source: local data frame [6 x 3]
Groups: exract11 [3]
exract11 chcscncr count
<fctr> <fctr> <int>
1 Active Gaming Devices (Wii Fit, Dance, Dance revolution) Yes 19
2 Active Gaming Devices (Wii Fit, Dance, Dance revolution) No 287
3 Aerobics video or class Yes 800
4 Aerobics video or class No 7340
5 Backpacking Yes 4
6 Backpacking No 38
I would like to achieve a table that gives the "yes" proportion of each type of sport, something like:
From
Type Ans Count
Sport A yes 45
Sport A no 55
Sport B yes 34
Sport B no 66
to:
Type p(yes)
Sport A 0.45
Sport B 0.34