[R] re order vector in order given by another vector

Henrique Dallazuanna wwwhsd at gmail.com
Thu Aug 7 13:58:53 CEST 2008


Try this:

xx[match(zz, xx)]

On Thu, Aug 7, 2008 at 8:20 AM, jimineep <jamesrperkins at hotmail.com> wrote:
>
> So imagine I have a vector:
>
> zz = c("a","c","d","b")
>
> and another vector:
>
> xx = c("d","c","a","b")
>
> I need to get xx in the same order as zz. I am sure this is very simple but
> I can't figure it out from the help pages for order or sort. Perhaps I'm not
> trying hard enough but its been bugging me for a while.... Can anyone help?
> --
> View this message in context: http://www.nabble.com/re-order-vector-in-order-given-by-another-vector-tp18868253p18868253.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O



More information about the R-help mailing list