Your representation of Data
is not very suitable for the task you want to do. Here are the steps you have to go through:
Extract the column lists from
Data
and "zip" them into a list of rows lists (or tuples). You have to use a custom zip function that can handle more than 2 or 3 lists:manyzip([L|Ists]) -> Fold = fun(List, Acc) -> lists:zipwith(fun(A,B) -> [A|B] end,List,Acc) end, Reversed = lists:foldl(Fold, [[E] || E <- L], Ists), [lists:reverse(E) || E <- Reversed].
- Sort the rows on the respective element. You can use lists:sort/2 with a comparison function like
fun(A,B) -> lists:nth(4, A) < lists:nth(4, B) end
, where4
is the index ofF_02_0010
in the zipped lists. - Convert the rows back to columns.
manyzip/1
can be used as is for this task too! - Restore their positions in the tuple.