I am trying to divide each row of my matrix by the sum of that same row:
a <- matrix(1:25,nrow=5,ncol=5)
a <- apply(a,1,function(x) x/sum(x))
this gives the intended result but it is structured in columns as opposed to rows:
[,1] [,2] [,3] [,4] [,5]
[1,] 0.01818182 0.03333333 0.04615385 0.05714286 0.06666667
[2,] 0.10909091 0.11666667 0.12307692 0.12857143 0.13333333
[3,] 0.20000000 0.20000000 0.20000000 0.20000000 0.20000000
[4,] 0.29090909 0.28333333 0.27692308 0.27142857 0.26666667
[5,] 0.38181818 0.36666667 0.35384615 0.34285714 0.33333333