![]() |
|
Functions | |
| apop_data * | apop_data_sort (apop_data *data, apop_data *sort_order, char asc, char inplace, double *col_order) |
Copyright (c) 2013 by Ben Klemens. Licensed under the modified GNU GPL v2; see COPYING and COPYING2.
| apop_data* apop_data_sort | ( | apop_data * | data, |
| apop_data * | sort_order, | ||
| char | asc, | ||
| char | inplace, | ||
| double * | col_order | ||
| ) |
Sort an apop_data set on an arbitrary sequence of columns.
The sort_order set is a one-row data set that should look like the data set being sorted. The easiest way to generate it is to use Apop_r to pull one row of the table, then copy and fill it. For each column you want used in the sort, assign a ranking giving whether the column should be sorted first, second, .... Columns you don't want used in the sorting should be set to NAN. Ties are broken by the earlier element in the default order (see below).
E.g., to sort by the last column of a five-column matrix first, then the next-to-last column, then the next-to-next-to-last, then by the first text column, then by the second text column:
I use only comparisons, not the actual numeric values, so you can use any sequence of numbers: (1, 2, 3) and (-1.32, 0, 27) work identically.
strcasecmp. [exercise for the reader: modify the source to use Glib's locale-correct string sorting.]| data | The data set to be sorted. If NULL, this function is a no-op that returns NULL. |
| sort_order | A apop_data set describing the order in which columns are used for sorting, as above. If NULL, then sort by the vector, then each matrix column, then text, then weights, then row names. |
| inplace | If 'n', make a copy, else sort in place. (default: 'y'). |
| asc | If 'a', ascending; if 'd', descending. This is applied to all columns; column-by-column application is to do. (default: 'a'). |
| col_order | For internal use only. In your call, it should be NULL; the Designated initializers syntax will takes care of it for you. |
inplace=='y' (the default), then this is the same as the input set.A few examples: