Skip to content
Prev 310326 / 398506 Next

the results of the SORT function differ from Scilab/Matlab for Complex Numbers

On 08/11/2012 4:42 PM, Cleber N.Borges wrote:
This should sort by modulus then argument (phase):

x[order(Mod(x), Arg(x))]

It does strange things if x happens to be real:

 > x <- (-5):5
 > sort(x)
  [1] -5 -4 -3 -2 -1  0  1  2  3  4  5
 > x[order(Mod(x), Arg(x))]
  [1]  0  1 -1  2 -2  3 -3  4 -4  5 -5

but that may be what you want.

Duncan Murdoch