Given a a datasummary output, I would like to sort the outcome by the value of one column. E.G. I want to arrange the datasummary output by the mean of those variables. Sadly, the approach I followed beneath will not work. Addionally I tried coef_map with an unnamed vector, but this does not work as well. Thanks.
library(modelsummary)
test <- datasummary(hp+mpg ~ mean+sd, data = mtcars)
coef.rename <- test@data %>% arrange(desc(mean)) %>% pull(1, name = 1)
datasummary(hp+mpg ~ mean+sd, data = mtcars, coef_rename= coef.rename)
The hacky way might be
library(modelsummary)
X = datasummary(mpg+hp+wt~mean+sd, data=mtcars)
X@table_dataframe = X@table_dataframe |> sort_by(~mean)
giving
X