[R] comparing characters

Giovanni Petris GPetris at uark.edu
Mon Nov 3 19:00:41 CET 2003


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/              ]
[__________________________________________________]




More information about the R-help mailing list