0

I'm using dplyr, kabble, and kableextra to create some tables in R. I'm converting the tibble outputs from dpylr chains for tables in a report. I'd like to have the rank included as a column in a tibble that I then pipe into a kabble table. Is there a way to do this using mark-up or perhaps an R package that has the numeric expressions for ranks (i.e., 1st, 2nd, 3rd)?

I've tried this, but with many ranks it is impractical. Something similar to LETTERS would be good.

expression('1^st')
expression('2^nd')
alistaire
  • 42,459
  • 4
  • 77
  • 117
elliot
  • 1,844
  • 16
  • 45
  • As for the *ordinals* (or *ranks*) see `english::ordinal` on [CRAN](https://cran.r-project.org/web/packages/english/index.html) or the [documentation](https://www.rdocumentation.org/packages/english/versions/1.1-4/topics/ordinal). – Rui Barradas Feb 17 '19 at 18:53
  • 1
    You can't make an atomic vector of expressions in R, but you can hold them in a list, which can be a column of a tibble, e.g. `tibble(expr = list(expression(1^st), expression(2^nd)))`. If you're quoting already, though, just use a character vector. – alistaire Feb 17 '19 at 19:03
  • @alistaire, thanks. Would you know of a package that might have these listed out? (or is this an opportunity to try my hand at making a package?). Thanks. – elliot Feb 17 '19 at 19:06
  • Ordinals? See the `english` package linked by Rui above. I've considered doing some more stuff to make [Unicode CLDR](https://github.com/unicode-cldr) more accessible from R, but I haven't done it yet. – alistaire Feb 17 '19 at 19:11
  • Sorry, I'm not looking for ordinals, but expressions (I think) - like, 1st, 2nd, 3rd, 4rth, 5th, etc. Thanks. – elliot Feb 17 '19 at 19:17
  • You could use `scales::ordinal`, though you'll have to insert the `^` and coerce to an expression if you want it formatted that way – alistaire Feb 17 '19 at 20:13

0 Answers0