miller
miller copied to clipboard
Rank
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 how to assign rank? Why in example for 30
the rank is 4
and not 3
?
Thank you
@aborruso https://en.wikipedia.org/wiki/Ranking#Standard_competition_ranking_(%221224%22_ranking)
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
I think this will most likely be mlr stats1 -a rank
.