[R] Sorting problem

Wacek Kusnierczyk Waclaw.Marcin.Kusnierczyk at idi.ntnu.no
Sun Mar 29 01:18:20 CET 2009


Stavros Macrakis wrote:
> On Sat, Mar 28, 2009 at 7:53 AM, Duncan Murdoch <murdoch at stats.uwo.ca> wrote:
>   
>> ...More generally, the xtfrm() function converts a vector into a numeric one that sorts in the same order. ...
>>     
>
> Thanks, I learn a lot just by reading the answers to other people's
> questions on this list.
>
> Some followup questions:
>
> 1) Where does the name 'xtfrm' come from?
> 2) Why isn't xtfrm of a numeric vector the identity function?
> 3) Similarly, why isn't xtfrm of a logical vector just as.integer of
> it? (as it is for factors)
> 4) Why is xtfrm(c(2,3,2)) => c(1,3,1) and not c(1,2,1) or for that
> matter c(2,3,2) (see point 2)?
>   


and one more;  ?xtfrm says: 

"     The default method will make use of '==', '>'  and 'is.na' methods
     for the class of 'x', but might be rather slow when doing so.
"

and yet:

    x = c(1i, 0i)
    is(x)
    # [1] "complex" "vector"

    xtfrm(x)
    # [1] 2 1

there is no xtfrm.complex, so the default should be called and it would
make use of '==', '>', and 'is.na' for the class 'complex'.  but this fails:

    0i > 1i
    # error: invalid comparison with complex values

how come?  (yes, it's again the flaw of complex being totally ordered
while '>' and relatives cannot be used to establish the order).

vQ




More information about the R-help mailing list