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

Philipp Pagel p.pagel at wzw.tum.de
Sat Mar 28 19:03:44 CET 2009


> 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
> 
> The same won't work if I try to order a data frame:
> > data.frame(matrix(c(3,1,2), 3,2))[c(3,1,2),]
>   X1 X2
> 3  2  2
> 1  3  3
> 2  1  1

Looks like everything is working as expected to me. So maybe you should
explain what result you would like to get.

cu
	Philipp

-- 
Dr. Philipp Pagel
Lehrstuhl für Genomorientierte Bioinformatik
Technische Universität München
Wissenschaftszentrum Weihenstephan
85350 Freising, Germany
http://mips.gsf.de/staff/pagel




More information about the R-help mailing list