There's more…

As discussed, the method works based on generic concepts and the class names. If the class name changed, then the behavior of the corresponding function will also change based on it. For example, if you remove the "robustSummary" class from the object x then the print() function will work differently:

        > y <- unclass(x)
> y
[1] 13 21 19 18 21 16 21 24 17 18 12 18 29 17 18 11 13 20 25 18
15 19 21 21 7 12 23 31 16
[30] 19 23 15 25 19 15 25 25 16 29 15 26 29 23 24 20 19 14 27
22 26
> class(y) <- "robustSummary"
> y
Median 19
Median Absolute Deviation (MAD) 5.9304
First Quartile (Q1) 16
Third Quartile (Q3) 23.75

In the first block of code and output, the class x has been removed and assigned the new object into y. Then the generic function print() has been called. The output is just the internal elements printed into the console.

However, later on, when the robustSummary class has been assigned into the object y, then the print() function behaves differently. This is the beauty of OOP.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset