first by chr number (all chr1 go first, then all chr3, then all chr5, etc.) and within that by column 1 in ascending order. that is, the resulting array should look like that:[0] [1] [0] chr1 10 [1] chr3 20 [2] chr1 30 [3] chr3 5 . . . [n] chr5 5
the code I'm trying to use is:[0] [1] [0] chr1 10 [1] chr1 30 [2] chr3 5 [3] chr3 20 . . . [n] chr5 5
For a small dataset, it seems to work okay, but for real data the result is somewhat random - perhaps my test dataset is just biased. Is there some kind of mistake or the whole thing doesn't make any sense at all? I would really appreciate any help. Thanks in advance!my @sortedtda; my @chrnums; my @coords; $i=0; for (@twodarray) { push @chrnums, $twodarray[$i][0]=~ (/(\d+)/); push @coords, $twodarray[$i][1]=~ (/(\d+)/); ++$i; } @sortedtda = @twodarray[ sort { $coords[$a] <=> $coords[$b] || $chrnums[$a] <=> $chrnums[$b] } 0..$#twodarray ];
In reply to Sorting a two-dimensional array by two columns by a11
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |