I want to use the size of a group as part of a groupwise operation in dplyr::summarise
.
E.g calculate the proportion of manuals by cylinder, by grouping the cars
data by cyl
and dividing the number of manuals by the size of the group:
mtcars %>%
group_by(cyl) %>%
summarise(zz = sum(am)/group_size(.))
But, (I think), because group_size
is after a grouped tbl_df
and .
is ungrouped, this returns
Error in mutate_impl(.data, dots) : basic_string::resize
Is there a way to do this?