The main problem is that R is inconsistent here. There are lots of
branches through the sort() code. Greg showed one. Here are four more
> sort(y, method="quick")
[,1] [,2]
A15
B26
C37
D48
> names(y) <- letters[1:8]
> sort(y)
h g f e d c b a
1 2 3 4 5 6 7 8
>
Martin Maechler wrote:
> > "AndyL" == Liaw, Andy <[EMAIL PROTECTED]>
> > on Tue, 4 Oct 2005 13:51:11 -0400 writes:
>
> AndyL> The `problem' is that sort() does not doing anything special when
> given
> AndyL> a matrix: it only treat it as a vector. After sorting, it copies
>
> "AndyL" == Liaw, Andy <[EMAIL PROTECTED]>
> on Tue, 4 Oct 2005 13:51:11 -0400 writes:
AndyL> The `problem' is that sort() does not doing anything special when
given
AndyL> a matrix: it only treat it as a vector. After sorting, it copies
AndyL> attributes of the original
The `problem' is that sort() does not doing anything special when given
a matrix: it only treat it as a vector. After sorting, it copies
attributes of the original input to the output. Since dimnames are
attributes, they get copied as is.
Try:
> y <- matrix(8:1, 4, 2, dimnames=list(LETTERS[1:4]
Not sure if this is the correct forum for this, but I've found what I
would consider to be a potentially serious bug to the unsuspecting user.
Given a numeric vector V with class labels in R, the following calls
1.
> sort(as.matrix(V))
and
2.
>as.matrix(sort(V))
produce different ouput. Th