分配类

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

Richie Cotton

Data Evangelist at DataCamp

(x <- rexp(10))
0.195051 2.191040 0.498703 0.976122 0.299001
0.105187 0.090073 2.328233 3.043201 2.129631
class(x) <- "random_numbers"
x
0.195051 2.191040 0.498703 0.976122 0.299001
0.105187 0.090073 2.328233 3.043201 2.129631
attr(,"class")
"random_numbers"
R 中的 S3 与 R6 面向对象编程
class(x)
"random_numbers"
typeof(x)
"double"
R 中的 S3 与 R6 面向对象编程
is.numeric(x)
TRUE
length(x)
10
mean(x)
1.1856
R 中的 S3 与 R6 面向对象编程

总结

  • 您可以重写class()
  • 不会破坏现有功能
R 中的 S3 与 R6 面向对象编程

开始练习!

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

Preparing Video For Download...