Skip to content
Prev 243698 / 398506 Next

Arrange elements on a matrix according to rowSums + short 'apply' Q

Hi Aaron,

Following up on Ivan's suggestion, if you want the column order to
mirror the row order...

mo <- order(rowSums(MAT), decreasing=TRUE)
MAT2 <- MAT[mo, mo]

Also, you don't need all those extra c() calls when creating
inputData, just the outermost one.

Regarding your second question, your statements...

TMAT <- apply(t(MAT), 2, function(X) X/sum(X))
TMAT <- t(TMAT)

is actually just a complicated way of doing this...

TMAT <- MAT / rowSums(MAT)

You can confirm that by doing it your way and then this...

TMAT == MAT / rowSums(MAT)

...and you should see a matrix of TRUE values

Michael
On 2 December 2010 20:43, Ivan Calandra <ivan.calandra at uni-hamburg.de> wrote: