Skip to content

small inconsistency in sort

2 messages · Torsten Hothorn, Brian Ripley

#
Hi, 

if an atomic with colnames / rownames attribute is sorted, its names are
not sorted in the appropriate way: 

R> a <- matrix(1:5, ncol=5) 
R> colnames(a) <- paste("V", 1:5, sep="")
R> a  
     V1 V2 V3 V4 V5
[1,]  1  2  3  4  5
R> sort(a, dec=TRUE)
     V1 V2 V3 V4 V5
[1,]  5  4  3  2  1
R> 

?sort states that x is `a numeric or complex vector' but sort only checks
if `is.atomic(x)' causing the small problem. 

best,

Torsten
#
On Tue, 3 Dec 2002, Torsten Hothorn wrote:

            
Where is the inconsistency?  Nothing I can see says that arbitrary
attributes of a vector will be sorted, and a (numeric or complex) array
*is* a (numeric or complex) vector with some extra attributes.

How can one possibly sort a matrix *and* its dimnames except for
one-dimensional arrays?  Sorting a matrix makes no sense except when it is
regarded as a vector, and if that makes sense it probably also makes sense
to leave the dimnames unchanged.