Arraymultisort()

I have an array with integer and non integer data like this.
1
2.125
3.0625
10
etc.

I have tried ArrayMultiSort(vMyArray,cr(),tab(),“1;r;n”), ArrayMultiSort(vMyArray,cr(),tab(),“1;n”) and ArrayMultiSort(vMyArray,cr(),tab(),“1;r”). The closest result I get is

1
10
2.125
3.0625

Is there a way to get a true numeric sort with an array?

Use arraynumericsort(

The Panorama X version of this command/function has overcome the limitations in the various custom statements we had in Panorama 6, for sorting arrays numerically.

Arraymultisort is still useful, if you want to sort based on a column of a 2 dimensional array, but its numeric feature was never designed to handle anything but positive integers.

Hi Dave,

My actual data is a multidimensional array. It is actually column 13 that I need to sort the array by. Is there a way to use arraynumericsort( function to sort a 2 dimensional array?

As the author of the arraymultisort statement, I should be able to tweak the code to fix your problem but I no longer have the original code - maybe Jim or Dave has it and could send it to me?

In the interim, my only suggestion is that you put columns 1 to 12, column 13 and columns 14 to 99 into three variables (using arraybuild, arrayfilter and arrayrange), sort the column 13 array using arraynumericsort and re-assemble them using arraymerge.

It’s clumsy but it will do the job - that’s actually what arraymultisort does.

OK, I found it. I’ll see if I can add that extra functionality.

Michael, use the Open View wizard with the +Libraries button selected and search for arraymultisort and you will find the code there.

Ok, I just saw your additional post that you already found the info.

That’s not true - arraymultisort works differently. My memory was faulty, going back 10 years.

I had to test to be sure, but it looks like this is relatively easy to do. arraynumericsort( gets the numerical value of each element in much the same that the val( function does it. As long as the number comes first, you can have any additional text you like after it, so you could use arrayfilter( to add one additional column in front of the rest of the array, with the added column being a copy of your 13th column. Then you would do the arraynumericsort( and then strip off that added column.

Let’s say you are using carriage returns to separate the rows, and tabs to separate one item from the next on each row.

theArray = arrayfilter(theArray,cr(),{array(import(),13,tab())+tab()+import()})
theArray = arraynumericsort(theArray,cr())
theArray = arrayfilter(theArray,cr(),{arrayrange(import(),2,-1,tab())})

This will also sort a column of integers correctly so I can easily modify the arraymultisort code to do that.

Steve

I checked out the arraymultisort statement and its numeric sort option does sort floating point numbers and also handles negative numbers, despite what (my) documentation says.

Can you check that for me?