【问题标题】:Different values when using summary() and max, min and mean in R在R中使用summary()和max、min和mean时的不同值
【发布时间】:2015-07-26 02:50:58
【问题描述】:

我正在尝试获取数据框中列的最大值、最小值和平均值。当我使用最大值、最小值和平均值时,我得到的一些值与我使用时的值不同,summary()

> max(count1,na.rm=TRUE)
[1] 202034

> min(count1,na.rm=TRUE)
[1] 0

> mean(count1,na.rm=TRUE)
[1] 8498.78

> summary(count1,na.rm=TRUE) 
Min.  1st Qu.  Median    Mean 3rd Qu.    Max.    NA's 
0        1555    3668    8499    8535  202000   58297 

【问题讨论】:

  • 比较summary(mtcars$mpg) ;mean(mtcars$mpg),然后比较options(digits=10); summary(mtcars$mpg) ;mean(mtcars$mpg)

标签: r


【解决方案1】:

summary.default 函数有一个 digits 参数:

summary(object, ..., digits = max(3, getOption("digits")-3))

由于默认 getOptions("digits")7,因此您只能获得 4 数字。之后的所有内容都被四舍五入(致电signif())。您可以按照user20650 设置的建议进行更改,例如

options(digits=10)

或者,如果您只想针对此特定呼叫进行更改:

summary(count1, digits = 10)

【讨论】:

    猜你喜欢
    • 2012-08-26
    • 2013-04-26
    • 2021-12-24
    • 1970-01-01
    • 1970-01-01
    • 2014-03-15
    • 2021-11-06
    • 1970-01-01
    • 2019-01-26
    相关资源
    最近更新 更多