[R] Idiom for column operations?

Rob Steele rob at fatkat.com
Tue Oct 26 23:00:13 CEST 2004


Is there a better way to express operations between matrices and column 
vectors than transposing the matrix twice?

This is the kind of thing I'm talking about:

m = matrix(1:20, 3, 4)
v = colSums(m)

t(t(m) / v)   ## <--  kinda ugly, ain't it?

I thought of converting the column vector to a matrix:

m / matrix(v, nrow = nrow(m), ncol = length(v), byrow = TRUE)

But that seems even worse.

Thanks!
Rob Steele




More information about the R-help mailing list