I will be using Rs built in dataset mtcars for this assignment.
To start, we can show the first few rows with head() and describe its structure with str(). Then, using generic functions print() and summary()we can further inspect the data.
Then, we will create 2 objects and inspect:
You can tell whether an object uses S3 or S4 by using functions class() and isS4(). The class() function tells us an object’s class, and isS4() checks whether it belongs to the S4 system. You can tell an object’s type by using typeof(), which returns its storage type. We can also use str() to examine its structure. Generic functions in R like these select a specific method based on an object’s class. The main difference between S3 and S4 is that S3 is simpler and more flexible, while S4 is more structured. S3 classes and methods are easier to create, but S4 requires you to define classes and methods using functions like setClass() and setMethod(). S4 also allows you to set specific data types for an object’s slots, which helps prevent errors.
GitHub link
Leave a Reply