【问题标题】:Describe function not working in R描述在 R 中不起作用的函数
【发布时间】:2015-04-16 02:56:36
【问题描述】:

我正在尝试使用 psych 包中的 describe 函数。但是,我收到以下错误:

描述中的错误(ToothGrowth): description 必须是长度至少为 1 的字符串

我确保重新安装包,加载它,并从数据集库附加一个示例 data(ToothGrowth),但仍然收到此错误。

R version 3.1.2 (2014-10-31) 
Platform: x86_64-w64-mingw32/x64 (64-bit) 

locale: 
[1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252 
[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C 
[5] LC_TIME=English_United States.1252 

attached base packages: 
[1] tools tcltk stats4 splines parallel grid compiler 
[8] stats graphics grDevices utils datasets methods base 

【问题讨论】:

  • 为我工作。你能发布sessionInfo()的输出吗?
  • R 版本 3.1.2 (2014-10-31) 平台:x86_64-w64-mingw32/x64(64 位)语言环境:[1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States。 1252 [3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C [5] LC_TIME=English_United States.1252 附加基础包:[1] 工具 tcltk stats4 样条平行网格编译器 [8] 统计图形 grDevices utils 数据集方法库
  • 它看起来不像 psych 已加载。你做了library("psych") 吗?
  • @user20650 -> 已加载
  • 你有testthat 加载了吗?

标签: r psych


【解决方案1】:

问题是testthat::describe 覆盖psych::describe

library(psych)
data(ToothGrowth)
describe(ToothGrowth)
# Warning in FUN(newX[, i], ...) :
#   no non-missing arguments to min; returning Inf
# Warning in FUN(newX[, i], ...) :
#   no non-missing arguments to max; returning -Inf
#       vars  n  mean   sd median trimmed  mad min  max range  skew kurtosis   se
# len      1 60 18.81 7.65  19.25   18.95 9.04 4.2 33.9  29.7 -0.14    -1.04 0.99
# supp*    2 60   NaN   NA     NA     NaN   NA Inf -Inf  -Inf    NA       NA   NA
# dose     3 60  1.17 0.63   1.00    1.15 0.74 0.5  2.0   1.5  0.37    -1.55 0.08

library(testthat)
# Attaching package: ‘testthat’

# The following object is masked from ‘package:psych’:

#     describe    <-- overrides describe function of psych package

# The following object is masked from ‘package:sos’:

#     matches

describe(ToothGrowth)
# Error in describe(ToothGrowth) : 
#   description must be a string of at least length 1

一种解决方案是在psych 之前加载testthat。另一个就是说使用哪个describe函数:

psych::describe(ToothGrowth)

【讨论】:

  • 我会推荐@Pascal 的第二个解决方案psych::describe(ToothGrowth)。这更容易维护,因为包是在函数旁边立即指定的。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-09-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-05-06
相关资源
最近更新 更多