[R] Selecting elements from a vector (a simple question with weird results)

Johannes Huesing johannes at huesing.name
Sat Mar 28 21:50:44 CET 2009


Tal Galili <tal.galili at gmail.com> [Sat, Mar 28, 2009 at 06:48:36PM CET]:
> Hello people.
> 
> I wish to reorder a simple vector of numbers by another vector of the order
> (and then do the same, but with a data frame rows)
> 
> I try this (which doesn't work) :
> > aa <- c(3, 1 ,2 )
> > aa[aa]
> [1] 2 3 1

To my mind, it does what you told it to, and therefore "works"
in my book. The routine orders the numbers by placing the third element
first, the first second, and the second third.

Maybe aa[order(aa)] does what you mean it to do?

Best wishes


Johannes

-- 
Johannes Hüsing               There is something fascinating about science. 
                              One gets such wholesale returns of conjecture 
mailto:johannes at huesing.name  from such a trifling investment of fact.                
http://derwisch.wikidot.com         (Mark Twain, "Life on the Mississippi")




More information about the R-help mailing list