Assignment #7: Exploring R’s Object Oriented Systems (S3 & S4)
You can tell if it's S3 or S4 by checking its class. S3 objects are usually lists with a class name added, while S4 objects have to be defined first using setClass().
You can tell the class of an object by using class(). When using that on S3 it prints out "students_s3" and the class of S4 is "student_s4" as they are custom classes.
A generic function in R is summary(), which displays stats of the data frame and the average.
Differences between S3 and S4 are that S3 is simpler, where you make a list and give it a class name, while S4 is more strict, where you have to define the class first and say what data type goes inside.
Comments
Post a Comment