方法化思维

R 中的 S3 与 R6 面向对象编程

Richie Cotton

Data Evangelist at DataCamp

ch2_2-methodical-thinking.003.png

R 中的 S3 与 R6 面向对象编程
methods
R 中的 S3 与 R6 面向对象编程
methods("mean") # or methods(mean)
mean.Date     mean.default  mean.difftime mean.POSIXct 
mean.POSIXlt 
see '?methods' for accessing help and source code
R 中的 S3 与 R6 面向对象编程

ch2_2-methodical-thinking.009.png

R 中的 S3 与 R6 面向对象编程
methods(class = "glm") # or methods(class = glm)
add1           anova          coerce        
confint        cooks.distance deviance      
drop1          effects        extractAIC    
family         formula        influence     
initialize     logLik         model.frame   
nobs           predict        print         
residuals      rstandard      rstudent      
show           slotsFromS3    summary       
vcov           weights       
see '?methods' for accessing help and source code
R 中的 S3 与 R6 面向对象编程

 

 

 

methods() 返回 S3S4 方法

R 中的 S3 与 R6 面向对象编程
.S3methods(class = "glm")
add1           anova          confint       
cooks.distance deviance       drop1         
effects        extractAIC     family        
formula        influence      logLik        
model.frame    nobs           predict       
print          residuals      rstandard     
rstudent       summary        vcov          
weights       
see '?methods' for accessing help and source code
R 中的 S3 与 R6 面向对象编程
.S4methods(class = "glm")
coerce      initialize  show        slotsFromS3
see '?methods' for accessing help and source code
R 中的 S3 与 R6 面向对象编程

小结

  • methods() 为泛型查找方法
  • ... 或为某个
  • .S3methods() 仅查找 S3 方法
R 中的 S3 与 R6 面向对象编程

Let's practice!

R 中的 S3 与 R6 面向对象编程

Preparing Video For Download...