HarlanH/DataFrames.jl — pull request #177 by kmsquire (2013-02-02 21:00:33+00:00)
Title: RFC: Added generalized sorting routines (non-modifying only) to DataFrames.

Make `Sort.sort`, `Sort.sortby`, and `Sort.sortperm` work for `DataFrames`.

Notes:

* `sort*` functions expect an `AbstractVector`, so `DataFrame`s are wrapped in a `DFVector` type.
* `sort!` functions are not implemented.
* Accessing a row with `df[x,:]` produces another `DataFrame`, and it doesn't make much sense to compare two dataframes, so DataFrame rows are wrapped in a `DFRow` type for comparison.
* `Sort.By` was extended to accept numbers, strings, or vectors, and use those as indices into DataFrame columns, to allow sorting on particular columns
* All sorting is implemented in terms of `sortperm`
* TimSort is the default sort; DataFrames should use a stable sort, and are one place where chunks should be expected to be already sorted, which TimSort takes advantage of
* Note that the order of arguments change:

Old:
```julia
DataFrames.sortby(df::DataFrame, colname::String)`
```
New:
```julia
Sort.sortby(cols, df::DataFrame)
```

I think it would make more sense for the sort vector go first in `Sort.sortby`, in anticipation of keyword arguments that could be used to specify the sort algorithm, etc.

CC: @StefanKarpinski