Say I have a dataframe with two columns, such as
data.frame(experiment = rep(c('e1', 'e2'),each = 3),
outcomes = c('NH', 'NH', 'NH', 'H', 'NH', 'H'))
For each value in a column, I want to calculate the proportion of values that a particular value in a different column. So for my example, I want to calculate the proportion of outcomes in e1 and in e2 that are 'NH'. Thus, the final result is:
| experiment | Proportion |
|---|---|
| e1 | 1 |
| e2 | 0.333 |