[Rd] small inconsistency in sort
ripley@stats.ox.ac.uk
ripley@stats.ox.ac.uk
Tue Dec 3 14:51:02 2002
On Tue, 3 Dec 2002, Torsten Hothorn wrote:
> 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.
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.
--
Brian D. Ripley, ripley@stats.ox.ac.uk
Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel: +44 1865 272861 (self)
1 South Parks Road, +44 1865 272860 (secr)
Oxford OX1 3TG, UK Fax: +44 1865 272595