Hi

I have

>x<-matrix(c(1,2,3,4), ncol = 2)
>x
     [,1] [,2]
[1,]    1    3
[2,]    2    4

I'd like these two be divided by their column totals. so 1/3 and 2/3 and 3/7 
and 4/7. The obvious
>x/colSums(x)
          [,1]      [,2]
[1,] 0.3333333 1.0000000
[2,] 0.2857143 0.5714286

gives me the wrong results for off diagnal ones,  since it divides the first 
row by 3 and second by 7. The inelegant
>t(t(x)/colSums(x))
          [,1]      [,2]
[1,] 0.3333333 0.4285714
[2,] 0.6666667 0.5714286

gives me the right thing. I was wondering if there is any better way of 
getting what I want.

thanks

Alex

_________________________________________________________________
Get real-time traffic reports with Windows Live Local Search

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to