I have a matrix of 2 columns. I calculated the percentage contribution of each column by row to the overall using the formula below:
B = matrix (c(2,4,3,1,5,7,5,3,8,3,7,3),nrow=6,ncol=2)
sweep(B, 1, rowSums(B), FUN="/")
This gives the result below:
[,1] [,2]
[1,] 0.2857143 0.7142857
[2,] 0.5714286 0.4285714
[3,] 0.2727273 0.7272727
[4,] 0.2500000 0.7500000
[5,] 0.4166667 0.5833333
[6,] 0.7000000 0.3000000
However, I need to add weights to each row i.e. 1 for row 1 and 3 for row 2. How do I compute the weighted percentage contribution, please?