Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Ordering a list in Mathematica

  1. Jan 4, 2012 #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. Jan 4, 2012 #2


    User Avatar
    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]])
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook