Complete the code to define a new S4 class named "Person".
setClass("Person", slots = list(name = "character", age = [1]))
The age slot should be of type integer to store whole numbers representing age.
Complete the code to create a new object of class "Person" with name "Alice" and age 30.
alice <- new("Person", name = "Alice", age = [1])
The age slot expects an integer, so use 30L to specify an integer literal in R.
Fix the error in the method definition for the "show" function for class "Person".
setMethod("show", "Person", function(object) { cat("Name:", object@name, "\n") cat("Age:", object@[1], "\n") })
The slot name is case-sensitive and defined as age, so use object@age to access it.
Fill both blanks to define a method "birthday" that increases the age by 1 for a "Person" object.
setGeneric("birthday", function(object) standardGeneric("birthday")) setMethod("birthday", "Person", function(object) { object@[1] <- object@[2] + 1 return(object) })
The method should update the age slot by adding 1 to the current age.
Fill all three blanks to create a valid S4 class "Employee" that extends "Person" and adds a slot "salary" of type numeric.
setClass("Employee", slots = list([1] = [2]), contains = [3] )
The Employee class adds a salary slot of type numeric and extends the Person class.