Hi all, I?m having some trouble when trying to compare character values (to check if they are alphabetically ordered). Is it possible to do it in any way? Thanks for your help. Cheers, Aurora
What sort of trouble are you having? I just got the following from R 1.8.0: > "a"<"b" [1] TRUE > "a">"b" [1] FALSE > "ab"<"a" [1] FALSE > "ab">"a" [1] TRUE hope this helps. spencer graves Aurora Torrente wrote:> Hi all, > I?m having some trouble when trying to compare character values (to > check if they are alphabetically ordered). Is it possible to do it in > any way? > Thanks for your help. Cheers, > > Aurora > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-help
You could do something like that:> x <- sample(LETTERS, 10) > x[1] "K" "N" "C" "F" "R" "E" "L" "J" "S" "Q"> all.equal(order(x), 1:length(x))[1] "Mean relative difference: 0.5090909" When x is a numeric vector, I usually use> any(diff(x) < 0)although I don't know whether it's more efficient. HTH, Giovanni> Date: Mon, 03 Nov 2003 16:46:34 +0000 > From: Aurora Torrente <aurora at ebi.ac.uk> > Sender: r-help-bounces at stat.math.ethz.ch > Organization: EBI > Precedence: list > User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-GB; rv:0.9.4) > Gecko/20011128 Netscape6/6.2.1 > > Hi all, > I?m having some trouble when trying to compare character values (to > check if they are alphabetically ordered). Is it possible to do it in > any way? > Thanks for your help. Cheers, > > Aurora > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-help > >-- __________________________________________________ [ ] [ Giovanni Petris GPetris at uark.edu ] [ Department of Mathematical Sciences ] [ University of Arkansas - Fayetteville, AR 72701 ] [ Ph: (479) 575-6324, 575-8630 (fax) ] [ http://definetti.uark.edu/~gpetris/ ] [__________________________________________________]
Aurora Torrente wrote:> Hi all, > I?m having some trouble when trying to compare character values (to > check if they are alphabetically ordered). Is it possible to do it in > any way? > Thanks for your help. Cheers,"a" < "b" should work. If that's not your question, you have to be more specific. Uwe Ligges
On Mon, 2003-11-03 at 10:46, Aurora Torrente wrote:> Hi all, > I?m having some trouble when trying to compare character values (to > check if they are alphabetically ordered). Is it possible to do it in > any way? > Thanks for your help. Cheers, > > AuroraDepending upon what it is you are comparing, you may find differences from what you expect due to to your 'locale'. See ?Comparison for more information. HTH, Marc Schwartz
That?s what I needed. Thanks! Spencer Graves wrote:> What sort of trouble are you having? I just got the following from R > 1.8.0: > > "a"<"b" > [1] TRUE > > "a">"b" > [1] FALSE > > "ab"<"a" > [1] FALSE > > "ab">"a" > [1] TRUE > > hope this helps. spencer graves > >