Calculate row-wise proportions

following should do the trick

cbind(id = x[, 1], x[, -1]/rowSums(x[, -1]))
##   id       val0      val1      val2
## 1  a 0.08333333 0.3333333 0.5833333
## 2  b 0.13333333 0.3333333 0.5333333
## 3  c 0.16666667 0.3333333 0.5000000

Leave a Comment