I have two vectors, `X`

, `Y`

that represent positions of 2D points. Both of these vectors have a lot of duplicates, but there is no duplicate point (i.e. many points have same `x`

or `y`

coords, but no points have both `x`

and `y`

the same).

I am trying to sort these vectors such that they are first sorted by increasing `X`

and then by increasing `Y`

. Is there a straight-forward way to do it?

My current approach is to first sort X. Then, for each section of X that has the same value, sort the corresponding section of Y. Get these sorting indices (with `sortperm`

) and put their values in the master sorting vector. Continue until the end.

This seems kinda bad though