rainer.boehme at inf.tu-dresden.de
Wed Nov 16 11:29:01 CET 2005
# given this 2 x N matrix
N <- 10^5
A <- matrix(rnorm(2*N),2)
# use the following statement to sort the column vectors by their elements
in the i-th row
i <- 1
A <- A[,order(A[i,])]
Hope this helps,
> Good Morning Lorenzo,
> I had a look at ?sort and it said "For ordering along more than one
> variable, e.g., for sorting data frames, see 'order'." So I had a look
> at ?order... and popped down to the examples and it talks about
> ordering a dataframe - not the clearest of examples, but hey :-)
> Sometimes the obvious is the hardest to see :-)
> On 16/11/05, L.Isella <L.Isella at myrealbox.com> wrote:
>> Dear All,
>> I have a long array (say 2xN, with N of the order of 10^5 at least) made
>> up of couples of numerical values.
>> I would like to sort these N couples in increasing order of the value of
>> the numbers in the lower row.
>> It is very easy to use sort() to take care of the sorting of the lower
>> row, but then I also have to sort the upper row so that the values of
>> each couple still match.
>> I did it using a double loop, but for large N this is very slow.
>> This is really a bottleneck in my code...
>> Any suggestions?
>> R-sig-finance at stat.math.ethz.ch mailing list
> R-sig-finance at stat.math.ethz.ch mailing list
More information about the R-sig-finance