Ordering a list in Mathematica

  1. Hi everyone,

    Is it possible to order a list of (x,y) coordinates in Mathematica by x, then y? I currently have a number of data files in which there are 5 columns: x, y, area, circularity, radius. I would like to order the list by x and y coordinates while keeping the rows intact.

    Thank you
     
  2. jcsd
  3. CompuChip

    CompuChip 4,299
    Science Advisor
    Homework Helper

    There is
    Code (Text):

    Sort[list, p]
    sorts using the ordering function [i]p[/i].
     
    For p you could use something like
    Code (Text):

    p[a_, b_] := (a[[1]] < b[[1]]) || (a[[1]] == b[[1]] && a[[2]] < b[[2]])
     
     
Know someone interested in this topic? Share a link to this question via email, Google+, Twitter, or Facebook