1

(I'm new here so hopefully I am asking this in the correct way).

I am using Rmarkdown to create a summary table, and am using dfSummary within the summarytools package. I have created the table using this code:

enter image description here

enter image description here

Here is a picture of my current R-markdown:

enter image description here

I would like the order of the results for character variables to be listed in order of descending frequency, not alphabetical. I have read many pages summarize the package but cannot find an answer. Any help would be great!

Phil
  • 7,287
  • 3
  • 36
  • 66
Shani
  • 21
  • 1
  • Please provide a reproducible example of your problem instead of screenshots – Phil Jan 11 '21 at 20:49
  • Hello, welcome to Stackoverflow. You might want to provide a reproducible example to help others to answer your question. Please check [this](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) post. [reprex](https://reprex.tidyverse.org/) package is also a good way to start. – Duccio A Jan 11 '21 at 21:39

1 Answers1

1

There is no option to do that in summarytools directly. (You can open an issue on the GitHub project page for a feature request.) The ordering by frequency is done only when there are more distinct values than allowed by max.distinct.values.

The easiest way to proceed would be to recode your character variable with forcats::fct_infreq:

library(forcats)
df$var_f <- fct_infreq(df$var)

The order of factor levels will be preserved in the the results.

Dominic Comtois
  • 10,230
  • 1
  • 39
  • 61