From hadley at rice.edu  Thu Feb  4 01:20:47 2010
From: hadley at rice.edu (Hadley Wickham)
Date: Wed, 3 Feb 2010 18:20:47 -0600
Subject: [Rd] Proposal unary - operator for factors
In-Reply-To: <4B6A11EC.7040606@stats.uwo.ca>
References: <f8e6ff051002031510m4dca3c8co8d69c3117e1deab4@mail.gmail.com> 
	<77EB52C6DD32BA4D87471DCD70C8D7000275B14F@NA-PA-VBE03.na.tibco.com> 
	<f8e6ff051002031538ub5c2892ya83806ad3fe025a0@mail.gmail.com> 
	<77EB52C6DD32BA4D87471DCD70C8D7000275B165@NA-PA-VBE03.na.tibco.com> 
	<4B6A11EC.7040606@stats.uwo.ca>
Message-ID: <f8e6ff051002031620t84ad1d6tb859ccd5825052fe@mail.gmail.com>

>> Currently, for numeric a you can do either
>> ? order(-a)
>> or
>> ? order(a, decreasing=FALSE)
>> For nonnumeric types like POSIXct and factors only
>> the latter works.
>>
>> Under my proposal your
>> ? order(a, -b, c, d)
>> would be
>> ? order(a, b, c, d, decreasing=c(FALSE,TRUE,FALSE,TRUE))
>> and it would work for any ordably class without modifications
>> to any classes.
>
> Why not use
>
> ?order(a, -xtfrm(b), c, -xtfrm(d))

That's a good suggestion.  You could make it even easier to read with
desc <- function(x) -xtfrm(x)

order(a, desc(b), c, desc(d))

Could you remind me what xtfrm stands for?

Thanks!

Hadley

-- 
http://had.co.nz/



[Rd] Proposal unary - operator for factors
Hadley Wickham