I want to count the percentage of the response "yes" in a column that contains "yes" and "no".
| Student | Response |
|---|---|
| S1 | yes |
| S2 | yes |
| S1 | no |
| S5 | yes |
| S5 | yes |
| S7 | no |
| S8 | no |
This is what I would like to get
| Student | Response | percentage |
|---|---|---|
| S1 | yes | 50% |
| S2 | yes | 100% |
| S1 | no | 50% |
| S5 | yes | 100% |
| S5 | yes | 100% |
| S7 | no | 0% |
| S8 | no | 0% |
This is what I have been working but I don't understand what's not working. Thanks!
df %>%
group_by(Student)%>%
summarize(sum_total = n(Response)%>%
filter(Response== "yes") %>%
summarize(sum_yes = n(Response))%>%
mutate(yes_percentage = scales::label_percent()(sum_yes/sum_total))