Module 7: R Objects S3 vs. S4
For this assignment, I used the built-in dataset mtcars from R (so I didn’t have to download anything). First I loaded it and checked the first few rows to confirm it worked. Step 1. Data mtcars is a data frame (32 rows × 11 columns). Since it’s a normal R dataset, it already comes with a class and lots of functions that work with it. Step 2. Can a generic function be assigned to this dataset? If not, why? A generic function is a function that chooses which method to run based on the class of the object you pass in (like print() , summary() , or plot() ). For mtcars , generic functions already work because mtcars has class "data.frame" (and also behaves like a list under the hood). For example, summary(mtcars) runs the summary.data.frame() method automatically. If I tried to use a generic function that has no method for a data frame, it wouldn’t know what to do (it would either fall back to a default method or error). That’s basically the “why not” case: the obj...