[R] Non-standard sorts on vectors

Cheng Peng cpeng at usm.maine.edu
Sat Aug 28 20:24:09 CEST 2010


The following code shows that the unlisted data frame assigns an index to
each member. When one sorts the data frame based on ULST, he in fact uses
the (implicit) indices of ULST but not the actual values! Therefore, your
guess is correct.

> test.vec=data.frame(c("A","F","C"))
> ULST=unlist(test.vec)
> ULST
c..A....F....C..1 c..A....F....C..2 c..A....F....C..3 
                A                 F                 C 
Levels: A C F

> sort(as.vector(ULST),index.return=T)
$x
[1] "A" "C" "F"

$ix
[1] 1 3 2

# also the rank and he index are different
> rank(ULST)
c..A....F....C..1 c..A....F....C..2 c..A....F....C..3 
                1                 3                 2 





-- 
View this message in context: http://r.789695.n4.nabble.com/Non-standard-sorts-on-vectors-tp2340431p2384591.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list