[R] Problem

Jonathan Rougier J.C.Rougier at durham.ac.uk
Fri May 3 08:35:55 CEST 2002


Hi Alessandro,

Your question is a bit confusing but I think that the standard
subscripting operation will do this for you.  If your first vector is
named "orig" and your permuted vector is "perm", and the matrix with
columns named "orig" is "X", then you want to use the command "X[, perm,
drop=FALSE]" (you may not need to put "drop=FALSE", see "help("[")"). 
This is exactly the same as doing "X[, match(perm, orig), drop=FALSE]",
and you can examine the command "match(perm, orig)" directly to see what
is going on.

Cheers, Jonathan.

Ambrosini Alessandro wrote:
> 
> Hello.
> I have a vector of about 1000 words. Now I make an example with 5 words.
> The vector is
> a b c d e
> after some works I obtained a matrix with the vector in the first row as
> 
> aa bb cc dd ee
> 1  0  1  1  0
> 
> After other passage I obtained another vector that has the same words but
> that not the same order of the first one. I obtained
> 
> dd ee cc aa bb
> 
> Now my problem is to find a new matrix starting from the one that I wrote
> before, changing the position of the columns, according to the order of the
> second vector.
> Using the example I want to obtain
> 
> dd ee cc aa bb
> 1  0  1  1  0
> 
> The real vector is very long and so I can't make  change of position of the
> columns manually.
> Thank you
> Alessandro
> 
> -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
> r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
> Send "info", "help", or "[un]subscribe"
> (in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
> _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._

-- 
Jonathan Rougier                       Science Laboratories
Department of Mathematical Sciences    South Road
University of Durham                   Durham DH1 3LE
tel: +44 (0)191 374 2361, fax: +44 (0)191 374 7388
http://www.maths.dur.ac.uk/stats/people/jcr/jcr.html
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list