Search code examples
rdplyrpipetidyversegroup

get the no. of observations in every level of factor after grouping by factors


in the data Arthritis of package 'vcd', after grouping by Treatment and Sex, i would like to get the no. and percentage of observations in every level (None, Some, Marked) of Improved. how to do it?


Solution

  • "count() lets you quickly count the unique values of one or more variables: df %>% count(a, b) is roughly equivalent to df %>% group_by(a, b) %>% summarise(n = n()) . count() is paired with tally() , a lower-level helper that is equivalent to df %>% summarise(n = n()) ."