'Getting col % from a base size

I'm trying to get an output for a multi-response table in col%. I can get a % from column total but not from a fixed based. How do I do it? For example

Past week used (Seg A, Seg B, Seg C) = Olive Oil: 80, 100, 150 Sunflower Oil: 35, 95, 105 Coconut Oil: 109, 209, 15

Segment sizes A=120, B=250, C=165

I need col% by each segment

So Seg A should be calculated as Olive Oil= 80/120; Sunflower Oil=35/120 & Coconut Oil=109/120

Similarly for Seg B & Seg C.

I'm using tidyr and dplyr to generate my outputs.

Any advice will be much appreciated.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source