Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rank #383

Open
agguser opened this issue Oct 26, 2020 · 4 comments
Open

Rank #383

agguser opened this issue Oct 26, 2020 · 4 comments

Comments

@agguser
Copy link

agguser commented Oct 26, 2020

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.

@aborruso
Copy link
Contributor

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

Thank you

@agguser
Copy link
Author

agguser commented Oct 26, 2020

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

@agguser
Copy link
Author

agguser commented Oct 28, 2020

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

@johnkerl
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants