具有崩溃 R 包的所有数字变量的摘要

Summary of all numeric variables with collapse R package

可以通过应用 collapse R 包中的 fsummariseacross 函数来获得多个变量的摘要。例如:

library(collapse)
library(magrittr)
wlddev %>% 
  fgroup_by(region, income) %>%
  fsummarise(across(PCGDP:GINI, fmean, w = POP))


                       region              income      PCGDP   LIFEEX     GINI
1         East Asia & Pacific         High income 29172.7552 76.83283 32.79182
2         East Asia & Pacific Lower middle income  1756.6480 64.25623 36.07647
3         East Asia & Pacific Upper middle income  2357.6168 68.40768 39.94810
4       Europe & Central Asia         High income 29335.5511 75.66616 32.25404
5       Europe & Central Asia          Low income   803.2234 62.45228 32.22326
6       Europe & Central Asia Lower middle income  2256.9684 68.48909 28.97857
7       Europe & Central Asia Upper middle income  7772.5035 68.01573 38.70512
8   Latin America & Caribbean         High income 10217.0626 73.04484 49.41109
9   Latin America & Caribbean          Low income  1317.9024 55.45075 41.10000
10  Latin America & Caribbean Lower middle income  1913.8993 63.86360 50.65115
11  Latin America & Caribbean Upper middle income  7564.8294 69.46947 52.90072
12 Middle East & North Africa         High income 25889.0715 72.38335 36.93006
13 Middle East & North Africa          Low income  1049.8255 63.62748 35.89218
14 Middle East & North Africa Lower middle income  2015.0739 65.55189 33.21199
15 Middle East & North Africa Upper middle income  4861.2074 66.74364 40.19273
16              North America         High income 37840.9568 75.54352 39.73948
17                 South Asia          Low income   471.7241 55.56794 37.24783
18                 South Asia Lower middle income   882.7061 60.19159 33.04111
19                 South Asia Upper middle income  1830.8876 70.30871 36.97996
20         Sub-Saharan Africa         High income  8253.2074 71.79170 39.18180
21         Sub-Saharan Africa          Low income   518.5847 52.03107 40.26600
22         Sub-Saharan Africa Lower middle income  1587.8770 52.07344 42.87172
23         Sub-Saharan Africa Upper middle income  6528.2845 58.35122 61.30462

想知道如何获取所有数值变量的摘要,类似这样(由于速度快,只有 collapse 解决方案)

wlddev %>% 
  fgroup_by(region, income) %>%
  fsummarise(across(num_vars(.), fmean, w = POP))

Error in cols2int(cols, d, nam) : 
  cols must be a function, character vector, numeric indices or logical vector!

任何提示,请。

我不确定你是否正在寻找这个。

library(collapse)
library(magrittr)
wlddev %>% 
  fgroup_by(region, income) %>%
  fsummarise(across(is.numeric, fmean, w = POP))