aa[order(aa)] is the same as sort, although sort is much quicker and
has lower memory requirements:
> aa <- rnorm(1000)
> all(aa[order(aa)] == sort(aa))
[1] TRUE
> system.time(sort(aa))
user system elapsed
7.270.088.25
> system.time(aa[order(aa)])
user system elapsed
29.58
Yes Johannes - That helped, thank you.
On Sat, Mar 28, 2009 at 11:50 PM, Johannes Huesing wrote:
> Tal Galili [Sat, Mar 28, 2009 at 06:48:36PM CET]:
> > Hello people.
> >
> > I wish to reorder a simple vector of numbers by another vector of the
> order
> > (and then do the same, but with a da
Tal Galili [Sat, Mar 28, 2009 at 06:48:36PM CET]:
> Hello people.
>
> 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
To my mind, i
Thanks Jorge ,
I mistakingly (and foolishly) confused a vector of ranking, to a vector of
ordering that ranked vector...
Patrick Burns explained to me that I was looking for:
aa[order(aa)]
df[order(df[,1]), ]
Sorry,
Tal
On Sat, Mar 28, 2009 at 9:08 PM, Jorge Ivan Velez
wrote:
>
> Dear Tal,
Dear Tal,
It works as it should. In this code:
# Data
aa <- c(3, 1 ,2 )
aa
[1] 3 1 2
aa[aa]
[1] 2 3 1
you are telling R to do the following: take the vector aa and select the
elements aa (in R language that is aa[aa]). If you look carefully, the third
element of aa is 2, the first is 3 and the
Thanks Patrick,
Sorry to have missed that!
Tal
On Sat, Mar 28, 2009 at 9:01 PM, Patrick Burns wrote:
> I presume you are looking for:
>
> aa[order(aa)]
>
> and
>
> df[order(df[,1]), ]
>
>
> Patrick Burns
> patr...@burns-stat.com
> +44 (0)20 8525 0696
> http://www.burns-stat.com
> (home of
> 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
7 matches
Mail list logo