R Object: S3 vs. S4
For this week's assignment, I went and used a dataset I am familiar with, which is mtcars. This dataset contains information about 32 cars. After loading the dataset using the data() function, I tested to see if generic functions and OO systems applied to it. After checking the class of mtcars using class(mtcars), R returned "data.frame", which in R is implemented using the S3 object system, which in turn makes mtcars an S3 object. Since it's an S3 object, other generic functions can also be applied to it, such as summary() and print() The main difference between S3 and S4 is the structure and formality. S3 is more informal and flexible; it allows for objects to be assigned a class without a strict definition. On the other hand, S4 is more formal, and it requires explicit class definitions using the setClass() function and object creation using new(). Overall, we can see that mtcars is an S3 object, which we can see by generic functions being applied to it; S4 would ...