Jump to content

Ranking methods: Difference between revisions

no edit summary
(GP)
No edit summary
Line 1,074:
Barry 41 4 6 3 6 5.00
Stephen 39 7 7 4 7 7.00
</pre>
 
=={{header|Mathematica}}==
<lang Mathematica>
data = Transpose@{{44, 42, 42, 41, 41, 41, 39}, {"Solomon", "Jason",
"Errol", "Garry", "Bernard", "Barry", "Stephen"}};
 
rank[data_, type_] :=
Module[{t = Transpose@{Sort@data, Range[Length@data, 1, -1]}},
Switch[type,
"standard", data/.Rule@@@First/@SplitBy[t, First],
"modified", data/.Rule@@@Last/@SplitBy[t, First],
"dense", data/.Thread[#->Range[Length@#]]&@SplitBy[t, First][[All, 1, 1]],
"ordinal", Reverse@Ordering[data],
"fractional", data/.Rule@@@(Mean[#]/.{a_Rational:>N[a]}&)/@ SplitBy[t, First]]]
 
fmtRankedData[data_, type_] :=
Labeled[Grid[
SortBy[ArrayFlatten@{{Transpose@{rank[data[[All, 1]], type]},
data}}, First], Alignment->Left], type<>" ranking:", Top]
 
Grid@{fmtRankedData[data, #] & /@ {"standard", "modified", "dense",
"ordinal", "fractional"}}
 
</lang>
 
{{out}}
<pre>
standard ranking:
1 44 Solomon
3 42 Errol
3 42 Jason
6 41 Barry
6 41 Bernard
6 41 Garry
7 39 Stephen
 
modified ranking:
1 44 Solomon
2 42 Errol
2 42 Jason
4 41 Barry
4 41 Bernard
4 41 Garry
7 39 Stephen
 
dense ranking:
1 39 Stephen
2 41 Barry
2 41 Bernard
2 41 Garry
3 42 Errol
3 42 Jason
4 44 Solomon
 
ordinal ranking:
1 44 Solomon
2 42 Errol
3 42 Jason
4 41 Barry
5 41 Bernard
6 41 Garry
7 39 Stephen
 
fractional ranking:
1 44 Solomon
2.5 42 Errol
2.5 42 Jason
5 41 Barry
5 41 Bernard
5 41 Garry
7 39 Stephen
</pre>
 
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.