with a data frame df like below
df
df <- data.frame(colors = c(\"red\", \"blue\", \"green\", \"red\", \"red\" , \"blue\"))
I c
You can either pipe this to a mutate( prop = count / sum(count) ) or directly within summarise with nrow(.). Something like this:
mutate( prop = count / sum(count) )
summarise
nrow(.)
df %>% group_by(colors) %>% summarise(count = n() / nrow(.) )
or
df %>% group_by(colors) %>% summarise(count = n() ) %>% mutate( prop = count / sum(count) )