[R] about the function order()
Laurent Gautier
laurent at cbs.dtu.dk
Sat Nov 24 20:45:27 CET 2001
Thomas Lumley wrote:
>
> On Sat, 24 Nov 2001, Laurent Gautier wrote:
>
> > Dear all,
> >
> >
> > I have recently experienced something with the function order I cannot
> > explain:
> >
> >
> > The help(order) (which I admit having overlooked before) rises even more
> > my confusion...
> >
> > The following lines made me think order() was returning the 'order' each
> > value in a vector would take when sorted.
> >
> > > a <- c(4.1, 3.2, 6.1)
> > > order(a)
> > [1] 2 1 3
> >
> > Doing
> > > plot(a, order(a)/length(a))
> > gave what I expected (an empirical distribution function).
> >
> >
> >
> > Hower the following made me think I have been misusing order():
> >
> > > a <- c(4.1, 3.2, 6.1, 3.1)
> > > order(a)
> > [1] 4 2 1 3
> > >
> > > a <- rnorm(50)
> > > plot(a, order(a)/50)
> >
> > My question is, what is really order() doing ?
>
> In a sense it's doing the opposite of what you thought.
(...)
You are perfectly right.... How amazing things once clear blur with
tiredness...
I guess I should go home and rest before doing anything else silly... =)
Thanks for being around on a saturday and giving a fast answer...
Laurent
--
Laurent Gautier CBS, Building 208, DTU
PhD. Student D-2800 Lyngby,Denmark
tel: +45 45 25 24 85 http://www.cbs.dtu.dk/laurent
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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