Atribuirea claselor

Programare orientată pe obiecte cu S3 și R6 în R

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"
Programare orientată pe obiecte cu S3 și R6 în R
class(x)
"random_numbers"
typeof(x)
"double"
Programare orientată pe obiecte cu S3 și R6 în R
is.numeric(x)
TRUE
length(x)
10
mean(x)
1.1856
Programare orientată pe obiecte cu S3 și R6 în R

Rezumat

  • Puteți suprascrie class()
  • Aceasta nu va afecta funcționalitatea existentă
Programare orientată pe obiecte cu S3 și R6 în R

Să exersăm!

Programare orientată pe obiecte cu S3 și R6 în R

Preparing Video For Download...