>>>>> "Giovanni" == Giovanni Petris <[EMAIL PROTECTED]>
>>>>> on Mon, 3 Nov 2003 12:00:41 -0600 (CST) writes:
Giovanni> You could do something like that:
>> x <- sample(LETTERS, 10) x
Giovanni> [1] "K" "N" "C" "F" "R" "E" "L" "J" "S" "Q"
>> all.equal(order(x), 1:length(x))
Giovanni> [1] "Mean relative difference: 0.5090909"
Giovanni> When x is a numeric vector, I usually use
>> any(diff(x) < 0)
Giovanni> although I don't know whether it's more efficient.
There's a builtin R function that is definitely even faster
(at least for largish vectors):
is.unsorted()
--
Regards,
Martin Maechler <[EMAIL PROTECTED]> http://stat.ethz.ch/~maechler/
Seminar fuer Statistik, ETH-Zentrum LEO C16 Leonhardstr. 27
ETH (Federal Inst. Technology) 8092 Zurich SWITZERLAND
phone: x-41-1-632-3408 fax: ...-1228 <><
______________________________________________
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help