默认情况下,函数skim() (在R package skimr中)创建的对象的方法按字母顺序排列变量。如何才能使此方法按汇总数据集中变量出现的顺序打印这些变量?
# 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发布于 2018-07-20 20:13:00
发生这种情况的原因在软件包的工作方式中非常深入,这意味着对您的问题的简短回答是否定的。但是,如果您愿意使用skim_df对象或执行skim_to_wide(),则实际上可以完成这一任务
so_l <- skimr::skim_to_list(mtcars)$numeric 您可以在一个很好的字符串中获得列表。
orig_order<- names(mtcars)
so_l$ordered_var_name <- factor(so_l$variable, levels = orig_order,
ordered = TRUE)然后,ANd数据将按您所需的顺序排列,但打印可能对您有用,也可能不适用。
您还可以尝试从github安装v2分支。它真的对印刷的工作方式进行了很多反思。
https://stackoverflow.com/questions/51383339
复制相似问题