I have: d <- sample(10:100, 9) o <- order(d) r <- d[o] How I can get d (in the original order), knowing only r and o? Thanks - Wolfram
r[order(o)] seems to work alright... Andy> From: Wolfram Fischer > > I have: > > d <- sample(10:100, 9) > o <- order(d) > r <- d[o] > > How I can get d (in the original order), knowing only r and o? > > Thanks - Wolfram > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html > >
Wolfram Fischer wrote:> I have: > > d <- sample(10:100, 9) > o <- order(d) > r <- d[o] > > How I can get d (in the original order), knowing only r and o? >r[order(o)]? > d=sample(10:100,9) > o=order(d) > r=d[o] > all(r[order(o)] == d) [1] TRUE tested and works for duplicates in d as well. Barry
Hi Wolfram, just use: r[order(o)] I hope it helps. Best, Dimitris ---- Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School of Public Health Catholic University of Leuven Address: Kapucijnenvoer 35, Leuven, Belgium Tel: +32/16/396887 Fax: +32/16/337015 Web: http://www.med.kuleuven.ac.be/biostat/ http://www.student.kuleuven.ac.be/~m0390867/dimitris.htm ----- Original Message ----- From: "Wolfram Fischer" <wolfram at fischer-zim.ch> To: <r-help at stat.math.ethz.ch> Sent: Monday, October 04, 2004 4:21 PM Subject: [R] inverse function of order()>I have: > > d <- sample(10:100, 9) > o <- order(d) > r <- d[o] > > How I can get d (in the original order), knowing only r and o? > > Thanks - Wolfram > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html >
On 4 Oct 2004 at 16:21, Wolfram Fischer wrote:> I have: > > d <- sample(10:100, 9) > o <- order(d) > r <- d[o] > > How I can get d (in the original order), knowing only r and o?Hi try to sort it again r[order(o)] (not sure about ties, though) Cheers Petr> > Thanks - Wolfram > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.htmlPetr Pikal petr.pikal at precheza.cz
On Mon, 4 Oct 2004 16:21:14 +0200 Wolfram Fischer wrote:> I have: > > d <- sample(10:100, 9) > o <- order(d) > r <- d[o] > > How I can get d (in the original order), knowing only r and o?r[order(o)] hth Z> Thanks - Wolfram > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html >
On Monday 04 October 2004 09:21, Wolfram Fischer wrote:> I have: > > d <- sample(10:100, 9) > o <- order(d) > r <- d[o] > > How I can get d (in the original order), knowing only r and o?Perhaps r[order(o)] Deepayan
On Mon, 4 Oct 2004, Wolfram Fischer wrote:> I have: > > d <- sample(10:100, 9) > o <- order(d) > r <- d[o] > > How I can get d (in the original order), knowing only r and o?d <- r d[o] <- r It's a simple inverse, as your subject suggests. -- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595
Wolfram Fischer wrote:> I have: > > d <- sample(10:100, 9) > o <- order(d) > r <- d[o] > How I can get d (in the original order), knowing only r and o?r[order(o)] Uwe Ligges> Thanks - Wolfram > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
r[ order(o) ] will give you the answer. More generally, x <- rnorm(100) identical(x, x[ order(x) ][ order(order(x)) ]) [1] TRUE On Mon, 2004-10-04 at 15:21, Wolfram Fischer wrote:> I have: > > d <- sample(10:100, 9) > o <- order(d) > r <- d[o] > > How I can get d (in the original order), knowing only r and o? > > Thanks - Wolfram > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html >
Wolfram Fischer <wolfram <at> fischer-zim.ch> writes:> I have: > d <- sample(10:100, 9) > o <- order(d) > r <- d[o] > How I can get d (in the original order), knowing only r and o?When order acts on a permutation of 1:n it is an involution, i.e. it is its own inverse, therefore: r[order(o)]
An alternate method that saves having to use order() again is r[o] <- r Doug On Mon, 2004-10-04 at 15:21, Wolfram Fischer wrote:> I have: > > d <- sample(10:100, 9) > o <- order(d) > r <- d[o] > > How I can get d (in the original order), knowing only r and o? > > Thanks - Wolfram > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html >
Maybe Matching Threads
- how to test the existence of a name in a dataframe
- Why the factor levels returned by cut() are not ordered?
- Inverse X'WX matrix from weighted linear regression
- sub() of matrix returns a vector and not a matrix
- How to change letters after space into capital letters