miller icon indicating copy to clipboard operation
miller copied to clipboard

Rank

Open agguser opened this issue 3 years ago • 4 comments

Is there a way to get "rank" instead of "counter"? E.g.

$ echo "10\n20\n20\n30" | mlr --c2p -N cat -n
n 1
1 10
2 20
3 20
4 30

But I want

r 1
1 10
2 20
2 20   # note that the rank is 2, not 3
4 30

The command to generate ranks of field 1 would be mlr … cat --rank 1.

agguser avatar Oct 26 '20 11:10 agguser

@agguser how to assign rank? Why in example for 30 the rank is 4 and not 3?

Thank you

aborruso avatar Oct 26 '20 13:10 aborruso

@aborruso https://en.wikipedia.org/wiki/Ranking#Standard_competition_ranking_(%221224%22_ranking)

agguser avatar Oct 26 '20 15:10 agguser

Workaround:

$ echo "x\n10\n20\n20\n30" | mlr --c2t cat |   
   awk -F "\t" -v OFS="\t" '
      NR == 1 { print "r", $0 }
      NR > 1 { ++n; if ($1 != p) { p = $1; r = n } print r, $0 }' |
   column -t -s $'\t' -o ' '
r x
1 10
2 20
2 20
4 30

agguser avatar Oct 28 '20 03:10 agguser

I think this will most likely be mlr stats1 -a rank.

johnkerl avatar Oct 28 '20 13:10 johnkerl