Reputation: 5580
By default, the print
method for object created with function skim()
(in R package skimr) sorts variables alphabetically. How can I get this method to print the variables in the order they appeared in the summarized dataset?
# Default (desired) order of variable names
names(iris)
#> [1] "Sepal.Length" "Sepal.Width" "Petal.Length" "Petal.Width"
#> [5] "Species"
# `skim()` sorts variables alphabetically
skimr::skim_with(numeric = list(hist = NULL))
skimr::skim(iris)
#> / ... the output was truncated manually ... /
#>
#> -- Variable type:numeric ---------------------------------------------
#> variable missing complete n mean sd p0 p25 p50 p75 p100
#> Petal.Length 0 150 150 3.76 1.77 1 1.6 4.35 5.1 6.9
#> Petal.Width 0 150 150 1.2 0.76 0.1 0.3 1.3 1.8 2.5
#> Sepal.Length 0 150 150 5.84 0.83 4.3 5.1 5.8 6.4 7.9
#> Sepal.Width 0 150 150 3.06 0.44 2 2.8 3 3.3 4.4
Upvotes: 0
Views: 256
Reputation: 6755
This happens for reasons that are pretty deep in how the package works, meaning that the short answer to your question is no. However, if you are willing to work with the skim_df object or do skim_to_wide() you can actually accomplish this
so_l <- skimr::skim_to_list(mtcars)$numeric
You can get the list in a nice string
orig_order<- names(mtcars)
so_l$ordered_var_name <- factor(so_l$variable, levels = orig_order,
ordered = TRUE)
ANd then the data will be in the order you want, but the print may or may not work for you.
You may also want to try installing the v2 branch from github. It really rethinks a lot about how the printing works.
Upvotes: 1