Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: MATA: sort descending


From   Jesper Kj�r Hansen <[email protected]>
To   <[email protected]>
Subject   st: RE: MATA: sort descending
Date   Sat, 10 Jun 2006 15:39:57 +0200

Roberta wrote:
> I have a matrix like this:
> 
> a=
> 3 6 8 2
> 2 3 5 1
> 
> I woluld like :
> b=
> 8 6 3 2
> 5 3 2 1
> 
> I have to sort the first row of a matrix in a descending 
> order in MATA.
> Is possible?
> 

Try the following:

. mata
------------- mata (type end to exit) -------------
: x = (3, 6, 8, 2) \ (2, 3, 5, 1)

: x
       1   2   3   4
    +-----------------+
  1 |  3   6   8   2  |
  2 |  2   3   5   1  |
    +-----------------+

: sort(x',-1)'
       1   2   3   4
    +-----------------+
  1 |  8   6   3   2  |
  2 |  5   3   2   1  |
    +-----------------+

: 

See -help mf_sort- for more information.

- Jesper K. Hansen

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index