I want to create a large proportion table that involves filtering out certain values based on one column and outputting the proportion of values equal to 0 and those greater than 0 in table. Here's an example of the data frame (df):
ID a b c d e f g
1 1 1 2 3 0 4 5 A
2 2 0 0 1 0 2 0 A
3 3 1 5 2 1 0 0 B
4 4 5 1 2 0 1 1 B
5 5 2 0 1 0 0 0 C
...
From this, I want to come up with the proportion that b=0 or b>0 IF column a>0. For your reference, I can get this information with the following code:
prop.table(table(df$b[df$a>0]!=0))*100
However, I want to do the same with columns c and d as well as e and f (same sort of pattern so that you're filtering out when c=0 and when e=0 to get those >0 and =0 proportions for d and f, respectively). Additionally, I would love to have this output all into a single table. Might look something like this:
b.perc d.perc f.perc
TRUE 75.00 20.00 66.67
FALSE 25.00 80.00 33.33
Any help is appreciated. Also, I would like to calculate the TRUE percentages across groups listed in column G, giving me an output like this:
b.perc d.perc f.perc
A 100.00 0.00 50.00
B 100.00 50.00 100.00
C 0.00 0.00 0.00