【问题标题】:Summary shown in R is short, many terms shown as "Other"R中显示的摘要很短,许多术语显示为“其他”
【发布时间】:2015-08-16 23:41:49
【问题描述】:

如何在不将任何值归类为“其他”的情况下显示完整的输出摘要?

summary(d)
     Date.of.Sale   City               Department      Product     
 1/18/2015 :  149   A:5290   Footwear Mens  : 538   13245  :  255  
 1/25/2015 :  149   B:2078   Home Furnishing:1937   15350  :  255  
 11/23/2014:  149   C:5088   Infant W-Wear  : 992   15352  :  255  
 11/30/2014:  149            Ladies Lower   :1735   15353  :  255  
 12/14/2014:  149            Ladies Upper   :1805   15355  :  255  
 12/21/2014:  149            Mens Lower     :2039   15356  :  255  
 (Other)   :11562            Mens Upper     :3410   (Other):10926  
            Sale      Predicted.Sale       Flag      
 0            :3963   0      :3279   Forecast: 1341  
 Not Available:1341   1      :1951   History :11115  
 1            :1145   2      : 946                   
 2            : 797   3      : 700                   
 3            : 557   4      : 572                   
 4            : 498   5      : 438                   
 (Other)      :4155   (Other):4570   

【问题讨论】:

  • 您可能正在寻找table 函数,例如table(d$Date.of.Sale)

标签: r summary


【解决方案1】:

除此之外:您的数据似乎有因子列,它们应该是数字。您可能想看看它,因为它可能会在以后的分析中给您带来问题。


就您对summary() 的调用而言,您可以调整maxsum 参数。我们在help(summary) 中发现,这可用于更改摘要中显示的信息量

ma​​xsum - 整数,表示应该为因子显示多少级别。

让我们看看这个在工作中的两列数据框示例 -

set.seed(12)
df <- data.frame(
    a = sample(letters[1:8], 1e3, TRUE), 
    b = sample(letters[1:10], 1e3, TRUE)
)

在没有其他参数的情况下调用summary(),我们会在每列摘要的底部列出“其他”。

summary(df)
#       a             b      
# d      :132   g      :118  
# c      :131   b      :108  
# f      :131   e      :106  
# a      :123   f      :104  
# g      :123   d      :103  
# e      :122   j      :103  
# (Other):238   (Other):358 

现在如果我们将maxsum 调整为所有列的最大唯一值的长度,我们会得到所有列出的值。

summary(df, maxsum = max(lengths(lapply(df, unique))))
#  a       b      
#  a:123   a: 94  
#  b:120   b:108  
#  c:131   c: 99  
#  d:132   d:103  
#  e:122   e:106  
#  f:131   f:104  
#  g:123   g:118  
#  h:118   h: 92  
#          i: 73  
#          j:103  

请注意,maxsum 也可以是 maxsum = length(Reduce(union, df)),这假设您正在使用数据框。

【讨论】:

    猜你喜欢
    • 2021-03-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-03
    • 2011-04-30
    • 1970-01-01
    相关资源
    最近更新 更多