5

Hello all and a happy new year,

I have a table of the accuracy and kappa output of different learning models and am using knitr::kable to display them.

I now want to order the models (rows) first by accuracy (highest at top to lowest at bottom) and then, within this ordering, order the rows according to highest to lowest Kappa. So I want to have accuracy as the most important order criteria but Kappa as second most important one. There are other columns in the table but these are the two i want to order the rows by.

I am rather unexperienced in this regard and highly appreciate your help. I am also open to other functions / libraries that produce nice tables in RMarkdown and that can help me with this issue.

Thank you and best, corkinabottle

corkinabottle
  • 141
  • 1
  • 7
  • 1
    pity this doesn't have an answer (it isn't a duplicate, imho): The question was how to sort a kable. Kable doesn't have methods for `base::order` or `data.table::setorder` or `dplyr::arrange`, so the answer ends up being "sort before you make the kable, as once in kable form, there's no way out". – tim Jan 16 '22 at 19:56

1 Answers1

1

I think I found the answer myself. If you have the data stored in a data frame (df) before, you can do the following:

df[order(df$Accuracy, df$Kappa, decreasing=TRUE),]
corkinabottle
  • 141
  • 1
  • 7