分享

使用skimr对数据进行描述性分析

 阿越就是我 2023-10-12 发布于上海

skimr提供了一种无摩擦的汇总统计方法,1行代码显示汇总统计,用户可以快速浏览以理解数据。可以处理不同的数据类型并返回一个skim df对象,该对象可以包含在管道中,阅读方式十分友好。

这个skimr包属于一个叫ropensci的组织,有很多好用的R包都属于这个组织,大家感兴趣的话可以去官网[1]探索。

  • 安装

  • 使用

  • 定制参数

安装

目前不支持从cran安装,只能通过github安装。

# install.packages("devtools")
devtools::install_github("ropensci/skimr")

使用

library(skimr)

使用非常简单,就是一个skim函数,支持的描述统计比summary更多。输的内容会按照数据类型给你呈现,也可以自己定制输出内容和格式。

skim(iris)

Table: Data summary



Nameiris
Number of rows150
Number of columns5
_______________________
Column type frequency:
factor1
numeric4
________________________
Group variablesNone

Variable type: factor

skim_variablen_missingcomplete_rateorderedn_uniquetop_counts
Species01FALSE3set: 50, ver: 50, vir: 50

Variable type: numeric

skim_variablen_missingcomplete_ratemeansdp0p25p50p75p100hist
Sepal.Length015.840.834.35.15.806.47.9▆▇▇▅▂
Sepal.Width013.060.442.02.83.003.34.4▁▆▇▂▁
Petal.Length013.761.771.01.64.355.16.9▇▁▆▇▂
Petal.Width011.200.760.10.31.301.82.5▇▁▇▅▃
skim(dplyr::starwars)

Table: Data summary



Namedplyr::starwars
Number of rows87
Number of columns14
_______________________
Column type frequency:
character8
list3
numeric3
________________________
Group variablesNone

Variable type: character

skim_variablen_missingcomplete_rateminmaxemptyn_uniquewhitespace
name01.003210870
hair_color50.944130120
skin_color01.003190310
eye_color01.003130150
sex40.95414040
gender40.9589020
homeworld100.894140480
species40.953140370

Variable type: list

skim_variablen_missingcomplete_raten_uniquemin_lengthmax_length
films012417
vehicles011102
starships011705

Variable type: numeric

skim_variablen_missingcomplete_ratemeansdp0p25p50p75p100hist
height60.93174.3634.7766167.0180191.0264▁▁▇▅▁
mass280.6897.31169.461555.67984.51358▇▁▁▁▁
birth_year440.4987.57154.69835.05272.0896▇▁▁▁▁

当然也支持管道符:

library(dplyr)
## 
## 载入程辑包:'dplyr'
## The following objects are masked from 'package:stats':
## 
##  filter, lag
## The following objects are masked from 'package:base':
## 
##  intersect, setdiff, setequal, union

iris %>% 
  group_by(Species) %>% 
  skim()

Table: Data summary



NamePiped data
Number of rows150
Number of columns5
_______________________
Column type frequency:
numeric4
________________________
Group variablesSpecies

Variable type: numeric

skim_variableSpeciesn_missingcomplete_ratemeansdp0p25p50p75p100hist
Sepal.Lengthsetosa015.010.354.34.805.005.205.8▃▃▇▅▁
Sepal.Lengthversicolor015.940.524.95.605.906.307.0▂▇▆▃▃
Sepal.Lengthvirginica016.590.644.96.236.506.907.9▁▃▇▃▂
Sepal.Widthsetosa013.430.382.33.203.403.684.4▁▃▇▅▂
Sepal.Widthversicolor012.770.312.02.522.803.003.4▁▅▆▇▂
Sepal.Widthvirginica012.970.322.22.803.003.183.8▂▆▇▅▁
Petal.Lengthsetosa011.460.171.01.401.501.581.9▁▃▇▃▁
Petal.Lengthversicolor014.260.473.04.004.354.605.1▂▂▇▇▆
Petal.Lengthvirginica015.550.554.55.105.555.886.9▃▇▇▃▂
Petal.Widthsetosa010.250.110.10.200.200.300.6▇▂▂▁▁
Petal.Widthversicolor011.330.201.01.201.301.501.8▅▇▃▆▁
Petal.Widthvirginica012.030.271.41.802.002.302.5▂▇▆▅▇

定制参数

尽管skimr提供了自己的默认值,但它是高度可定制的。用户可以指定自己的统计数据,改变结果的格式,为新类创建统计数据等。

大家可以去skimrgithub[2]看看哦,不过也没有多少东西了,最主要的就是这个skim函数。

参考资料

[1]

ropensci官网: https:///

[2]

skimr github: https://github.com/ropensci/skimr

以上就是今天的内容,希望对你有帮助哦!欢迎点赞、在看、关注、转发

    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多