areaOfCircle <- function(radius) {
pi * radius^2
}53 53. function, matrix questions
53.1 Problem 1: Area of a Circle
Create a function named areaOfCircle.
- It should take one argument called
radius. - It should return the area of a circle.
- Use R’s predefined constant
pi.
53.2 Problem 2: Upper-Right Quadrant
Create a function named upperRightQuadrant.
- The argument
datawill be a matrix or data frame. - The number of rows and columns will be even.
- Return the upper-right quadrant.
53.3 Problem 3: Input Validation
Modify upperRightQuadrant so that it stops with an error if the data does not have an even number of rows and columns.
53.4 Problem 4: General Quadrant Function
Create a function named getQuadrant.
- Argument
datais a matrix or data frame with even dimensions. - Argument
nindicates which quadrant to return:- 1 = upper left
- 2 = upper right
- 3 = lower right
- 4 = lower left
- 1 = upper left
- If
nis missing, return the upper-left quadrant. - Otherwise, stop with an error.