I am using the dplyr package. Let's suppose I have the below table.
Group | count |
---|---|
A | 20 |
A | 10 |
B | 30 |
B | 35 |
C | 50 |
C | 60 |
My goal is to create a summary table that contains the mean per each group, and also, the percentage of the mean of each group compared to the total means added together. So the final table will look like this:
Group | avg | prcnt_of_total |
---|---|---|
A | 15 | .14 |
B | 32.5 | .31 |
C | 55 | .53 |
For example, 0.14 is the result of the following calculation: 15/(15+32.5+55)
Right now, I was only able to produce the first column code that calculates the mean for each group:
summary_df<- df %>%
group_by(Group)%>%
summarise(avg=mean(count))
I still don't know how to produce the prcnt_of_total column. Any suggestions?