So I'm trying to get r to report the share of a certain variable taking on a specific value in a group. For example: Let`s consider a dataset which consists of groups 1,2 and 3. Now I would like to know the percentage a Variable1 takes on the value 500 in group 1,2 and 3 and incorporate this as a new vaiable. Is there a convenient way to get to a solution? So it should look something like this:
df
Group Var1 Var1_perc
1 0 50
1 400 50
1 500 50
1 500 50
and so on for the other groups