I have a grouped df with different lengths of groups. I want to count y/n events within each group. So if I have the following:
df <- data.frame(group = rep(1:4,times=c(20,10,17,8)),
outcome = rep(c("yes","yes","no","yes","no"),times = 11))
I want to summarize this in a way where I can see the frequency of yes and frequency of no in each group. something like:
df %>% group_by(group) %>%
summarise(freqyes = (. %>% filter(outcome=="yes") %>% n()) / n(),
freqyes = (. %>% filter(outcome=="no") %>% n()) / n())
except, that doesn't work.
The yes and no per group should add to 100.
Thanks.