数据框,错误的摘要

mai*_*lle 2 r summary dataframe

我有一个非常大的数据帧,称为FTSE.在这里他的结构.

str(FTSE)

'data.frame':   21167 obs. of  5 variables:
 $ Name         : Factor w/ 2 levels "FTSE MIB","FTSE MIB NET TOT ": 1 1 1 1 1 1 1 1 1 1 ...
 $ DateLastTrade: Factor w/ 18 levels "12/10/13","12/11/13",..: 9 9 9 9 9 9 9 9 9 9 ...
 $ LastPrice    : num  19091 19008 19002 19018 19018 ...
 $ Open         : num  19091 19091 19091 19091 19091 ...
 $ LastClose    : num  19021 19021 19021 19021 19021 ...
Run Code Online (Sandbox Code Playgroud)

我试着总结一下,我得到了:

summary(FTSE)
                Name        DateLastTrade     LastPrice          Open         LastClose    
 FTSE MIB         :10289   12/3/13 : 1370   Min.   :17750   Min.   :17811   Min.   :17805  
 FTSE MIB NET TOT :10878   12/4/13 : 1370   1st Qu.:18124   1st Qu.:18055   1st Qu.:18124  
                           12/6/13 : 1370   Median :18321   Median :18310   Median :18313  
                           12/2/13 : 1369   Mean   :18366   Mean   :18375   Mean   :18352  
                           12/5/13 : 1369   3rd Qu.:18595   3rd Qu.:18752   3rd Qu.:18697  
                           12/23/13: 1353   Max.   :19091   Max.   :19091   Max.   :19021  
                           (Other) :12966      
Run Code Online (Sandbox Code Playgroud)

请注意"LastPrice"列.如果我试着直接总结LastPrice(我在分析中实际需要的变量),我已经获得了这个,这与之前的有很大不同.

summary(FTSE$LastPrice)
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
  17750   18120   18320   18370   18600   19090 
Run Code Online (Sandbox Code Playgroud)

我在R上很新手,我真的无法理解为什么价值观会有所不同.这是一个四舍五入的问题?我已经阅读了很多关于此的答案,但我找不到统一结果的解决方案.我真的坚持这个问题.

感谢任何可以帮助我甚至尝试理解我的问题的人.问候

编辑shujaa:

max(FTSE$LastPrice) 
[1] 19091.3

FTSE[which.max(FTSE$LastPrice), ]
      Name DateLastTrade LastPrice    Open LastClose
1 FTSE MIB       12/2/13   19091.3 19091.3  19021.48
Run Code Online (Sandbox Code Playgroud)

42-*_*42- 7

这是一个四舍五入的问题.所有输出summary(FTSE$LastPrice)只有4位有效数字.如果您?summary在其Usage部分中查看,您会看到数字的默认值(作为命名参数)以及数字的默认值,因为选项会使您的数字变为4.

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

> getOption("digits")
[1] 7
Run Code Online (Sandbox Code Playgroud)

所以尝试:

summary(FTSE$LastPrice, digits=7)
Run Code Online (Sandbox Code Playgroud)

然而,一个未解决的问题仍然存在:为什么summary.data.frame函数的舍入程度不同,因为对于.default.data.frame方法,数字的默认参数是相同的?查看代码,您会看到summary.data.frame实际上首先summary.default在其固定值为digits = 12L的列上执行,稍后使用digits参数format.在我看来,帮助页面在这个区域的参数描述中有点模糊

digits: integer, used for number formatting with signif() (for summary.default) or 
                                                 format() (for  summary.data.frame).
Run Code Online (Sandbox Code Playgroud)

它完全忽略了data.frame列的默认(和固定)signif非常不同的事实.