I would like, when summarizing after grouping, to count the number of a specific level of another factor.
In the working example below, I would like to count the number of "male" levels in each group. I've tried many things with count, tally and so on but cannot find a straightforward and neat way to do it.
df <- data.frame(Group=replicate(20, sample(c("A","B"), 1)),
                 Value=rnorm(20),
                 Factor=replicate(20, sample(c("male","female"), 1)))
df %>% 
  group_by(Group) %>% 
  summarize(Value = mean(Value),
            n_male = ???)
Thanks for your help!
 
    