Divide one value in a data.frame by another in an alternate data.frame base on row and column meta data

I have one data frame with structure =

Gene    Transcript_ID   V1  V2  V3  V4
1   ENSG00000000003.14  ENST00000612152.4   0   6   0   3
2   ENSG00000000003.14  ENST00000373020.8   4   0   5   0
3   ENSG00000000003.14  ENST00000614008.4   0   0   0   0
4   ENSG00000000003.14  ENST00000496771.5   0   3   0   0

And I have the aggregated totals by Gene in another dataframe with structure =

Category                V1       V2      V3      V4    
1 ENSG00000000003.14     4.00       9.00    5.00    3.00  
2 ENSG00000000005.6      0.00       0.00    0.00    0.00  
3 ENSG00000000419.12     61.00      94.00  103.00   71.00  
4 ENSG00000000457.14     577.01     698.20  815.49  697.72 

I want to divide the values in data.frame 1, by the corresponding aggregate values in dataframe2 to give the relative proportions of all values.

Is there a nice simple bit of syntax someone can apply here please? Much appreciated!



Read more here: https://stackoverflow.com/questions/68473437/divide-one-value-in-a-data-frame-by-another-in-an-alternate-data-frame-base-on-r

Content Attribution

This content was originally published by Jed Lye at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: