Module #7 Assignment
For this assignment, I used the popular mtcars dataset for my analysis. My code is as follows:
data("mtcars")
head(mtcars)
list(mtcars)
#we can create generic functions for mtcars such as functions to find the
#mean or a function to create plots such as bar or scatter plots.
#S3 method
class(mtcars)
summary.mtcars <- function(object, ...) {
summary(object)
}
summary(mtcars)
#S3 methods can be applied
#s4 method
setClass("mtcarsClass", contains = "data.frame")
mtcars_s4 <- new("mtcarsClass", mtcars)
mtcars_s4
#S4 methods can be applied
How do you tell what OO system (S3 vs. S4) an object is associated with?
How do you determine the base type (like integer or list) of an object?
What is a generic function?
What are the main differences between S3 and S4?
In your GitHub, create two examples of S3 and S4.
Comments
Post a Comment