Module #7 R Object: S3 vs. S4 Assignment
To begin, we will use the provided mtcars dataset that is already packaged in R. Seeing as how the mtcars dataset is a data frame, any generic function should be able to be used with it. Due to its nature as a data frame, mtcars is also classified as an S3 object. However, an S4 object can be created that represents a car in the mtcars dataset. 1. How do you tell what OO system (S3 vs. S4) an object is associated with? You can use the class function to check the class of an object. If the class is a basic data type like “numeric”, “character”, or “data.frame”, then it’s an S3 object. If the class is a custom class that you defined using setClass, then it’s an S4 object. 2. How do you determine the base type (like integer or list) of an object? You can use the typeof function to determine the base type of an object. 3. What is a generic function? A generic function is a function that behaves differently based on the class of the input object. Examples of generic functions in ...