Question:
I have a list of list number (List<List<int>> listNumberCollection)
: 4 rows x 3 columns
1 3 9
6 5 6
3 2 7
2 7 2
How can I record of rank in column (smallest number is the 1st) so it should be:
1 2 4
4 3 2
3 1 3
2 4 1
My work: To order numbers in a column, I write a function for transposition (4 columns x 3 rows):
1 6 3 2
3 5 2 7
9 6 7 2
private List<List<Double>> MatrixTransposition(int k, List<List<Double>> listNumberCollection)
{
var revisedAllRanks = new List<List<Double>>();
for (int i = 0; i < k; i++ )
{
var allRanks = new List<Double>();
allRanks.AddRange(listNumberCollection.Select(value => value[i]));
revisedAllRanks.Add(allRanks);
}
return revisedAllRanks;
}
I tried to create a class named NumberRank with 2 properties (Number, Rank) and add into list of NumberRank
var revisedListNumberCollection = MatrixTransposition(k, listNumberCollection);
var listNumberRanks = new List<List<NumberRank>>();
foreach(List<Double> vectorsCollection in revisedListNumberCollection)
{
List<NumberRank> numberRanks = vectorsCollection.OrderByDescending(number => number).Select((number, i) => new NumberRank(number, i + 1)).ToList();
listNumberRanks.Add(numberRanks);
}
However, the result I get is ordered number with rank (first column: 1-1 2-2 3-3 6-4...), not what I want (1-1 6-4 3-3 2-2) Thanks!