From: Rob Biedenharn Date: 2009-03-20T12:01:42+09:00 Subject: Re: Complex sort of matrix possible, e.g. like Excel? On Mar 19, 2009, at 10:44 PM, Ryan Davis wrote: > On Mar 17, 2009, at 22:02 , RichardOnRails wrote: > >> I've got an array of rows (and thus a matrix) created user FasterCSV >> to extract data from a CSV file. I'd like to sort the matrix on >> column A ascending and, within that, column B descending. I looked >> at >> Matrix, but it doesn't seem to address that functionality. Is there >> a package that does, or do I have to write my own SuperMatrix >> inherited from Matrix? > > I'm kinda surprised nobody has said this: > > sorted = matrix.sort_by { |row| [row[0], -row[1]] } > > P.S. PLEASE trim to the relevant parts when you reply. In some of > your email on this thread you have two whole copies of nearly the > whole thread. Actually, it was suggested, but it assumes that row[1] has a -@ method. The OP confirmed later that the columns are text, not numbers. -Rob Rob Biedenharn http://agileconsultingllc.com Rob@AgileConsultingLLC.com