Peng Yu
2009-Dec-10 04:10 UTC
[R] What is the function to test if a vector is ordered or not?
I did a search on www.rseek.org to look for the function to test if a vector is ordered or not. But I don't find it. Could somebody let me know what function I should use?
Marc Schwartz
2009-Dec-10 04:21 UTC
[R] What is the function to test if a vector is ordered or not?
On Dec 9, 2009, at 10:10 PM, Peng Yu wrote:> I did a search on www.rseek.org to look for the function to test if a > vector is ordered or not. But I don't find it. Could somebody let me > know what function I should use?If by ordered, you mean sorted, then ?is.unsorted > is.unsorted(c(1, 4, 2, 6, 7)) [1] TRUE > is.unsorted(sort(c(1, 4, 2, 6, 7))) [1] FALSE If you mean to test a factor to see if it is an ordered factor, then ? is.ordered > is.ordered(factor(letters)) [1] FALSE > is.ordered(factor(letters, ordered = TRUE)) [1] TRUE HTH, Marc Schwartz
jim holtman
2009-Dec-10 04:24 UTC
[R] What is the function to test if a vector is ordered or not?
Try all(diff(order(yourVector)) == 1) On Wed, Dec 9, 2009 at 10:10 PM, Peng Yu <pengyu.ut@gmail.com> wrote:> I did a search on www.rseek.org to look for the function to test if a > vector is ordered or not. But I don't find it. Could somebody let me > know what function I should use? > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html<http://www.r-project.org/posting-guide.html> > and provide commented, minimal, self-contained, reproducible code. >-- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? [[alternative HTML version deleted]]