In R, whenever you write a function, by default the return object gets an S3 class but if you want to return an object that has S4 class, then you should explicitly define the class within the body of the function. In the previous recipes, you saw that the class has been defined outside of the function body. In this recipe, you will write a function that will return an object of the S4 class.
Creating a function to return an object of the S4 class
Getting ready
Your objective is to create a function that will calculate the following two types of descriptive statistics:
- Classical (mean and standard deviation)
- Robust (median and MAD)
The following is the vector of numeric values for the input. Your new function will take two...