当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


R语言 summary()用法及代码示例


R语言中的summary()函数是一个通用函数,用于生成各种模型拟合函数的结果汇总。

用法: summary(object, maxsum)

参数:
object:R对象
maxsum:整数值,指示应为因子显示多少级别

范例1:


# R program to illustrate
# summary function
  
# Initializing a character and
# integer vector
x <- c("GFG", "gfg", "Geek", "Geeks")
y <- c(1, 2, 3, 4)
  
# Calling summary() function
summary(x)
summary(y)

输出:

Length     Class      Mode 
4 character character 

Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
1.00    1.75    2.50    2.50    3.25    4.00 

范例2:


# R program to illustrate
# summary function
  
# Initializing a data set
state.region
  
# Calling summary() function to 
# get the factor for above data set
  
# Getting all the possible levels
summary(state.region)
  
# Getting maximum 3 levels
summary(state.region, maxsum = 3)

输出:

 [1] South         West          West          South         West         
 [6] West          Northeast     South         South         South        
[11] West          West          North Central North Central North Central
[16] North Central South         South         Northeast     South        
[21] Northeast     North Central North Central South         North Central
[26] West          North Central West          Northeast     Northeast    
[31] West          Northeast     South         North Central North Central
[36] South         West          Northeast     Northeast     South        
[41] North Central South         South         West          Northeast    
[46] South         West          South         North Central West         
Levels:Northeast South North Central West
Northeast         South North Central          West 
     9            16            12            13 
South    West (Other) 
  16      13      21 



相关用法


注:本文由纯净天空筛选整理自Kanchan_Ray大神的英文原创作品 Get Summary of Results produced by Functions in R Programming – summary() Function。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。