My dataset looks like this
Org_ID Market volume Indicator variable
1 100 1
1 200 0
1 300 0
2 50 1
2 500 1
3 400 0
3 200 0
3 300 0
3 100 0
And i want to summarize it by market TRx and org_id by calculating the % of 0 indicator variables in terms of market volume, as follows:
Org_ID % of 0's by market volume
1 83.3%
2 0%
3 100%
I tried subgroups but can't seem to be able to do this. Can anyone suggest what are some of the ways i can do?
with
dplyr
:Result:
Data: