On Sep 1, 2010, at 11:34 AM, David Winsemius wrote:


snipped
> t( apply(a, 1, function(x) colnames(a)[order(x)]) )
    [,1] [,2] [,3] [,4]
[1,] "A"  "C"  "B"  "D"
[2,] "A"  "C"  "B"  "D"
[3,] "D"  "B"  "C"  "A"
[4,] "B"  "A"  "C"  "D"
[5,] "C"  "D"  "B"  "A"

(apply returns a transposed version.)

That is over-broad. apply() only returns a "transposed" result of a matrix when the second argument is "1". It is (as I understand it anyway) supplying results for building another matrix in the default, for R, column-major order. If you start with rows uou gt columns. If your start with columns you get columns. And someday I will figure out how this generalizes to arrays.

apply(mtx, 1, I) #transposes
apply(mtx, 2, I)  #does not "transpose"

--
David Winsemius, MD
West Hartford, CT

______________________________________________
R-help@r-project.org 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