Posts

Showing posts from February, 2024

Module #7 R Object: S3 vs. S4 Assignment

Image
 To begin, we will use the provided mtcars dataset that is already packaged in R. Seeing as how the mtcars dataset is a data frame, any generic function should be able to be used with it.  Due to its nature as a data frame, mtcars is also classified as an S3 object. However, an S4 object can be created that represents a car in the mtcars dataset. 1. How do you tell what OO system (S3 vs. S4) an object is associated with? You can use the class function to check the class of an object. If the class is a basic data type like “numeric”, “character”, or “data.frame”, then it’s an S3 object. If the class is a custom class that you defined using setClass, then it’s an S4 object. 2. How do you determine the base type (like integer or list) of an object? You can use the typeof function to determine the base type of an object. 3. What is a generic function? A generic function is a function that behaves differently based on the class of the input object. Examples of generic functions in ...

Module #6 Doing Math Part 2

Image
 1. My R Code for question one is  Running this gives the following output: 2.  My R code for question two is This gives the following output: 3. My R code for question 3 is the following:  Which gives the output:

Module #5 Doing Math

Image
The purpose of this assignment is to learn more about how matrices function by finding the inverse and determinant of two matrices, A and B. We begin this process by creating the two matrices, A uses numbers 1 through 100 and reshapes it into a 10x10 matrix. B uses numbers 1 through 1000 and shapes it into 10x100 matrix.  Calculating the inverse of the matrices is quite simple in R and can be done with the solve() function. However, this does not guarantee that every matrix in R has an inverse which is immediately apparent when attempting to use this function on matrix A.  Upon running this function in R we are met with an error indicating there is no inverse. This is supported by running another function, the det() function which is used to find the determinant of A. Matrices cannot have an inverse if the determinant is zero.  Moving on to matrix B, we are met with another error running the solve() function on it.  This error indicates that matrix B is not square ...

Module #4 Programming Structure in R

Image
These are the two outputs created with my R code, the first being the boxplot and the second being a histogram.  Some of my observations in the boxplot are that the median blood pressure for the high category appears to be higher than that for the low category, the interquartile range is larger for the high category which suggests that there is more variability in blood pressure readings among those in that category, and that there may be an association between higher blood pressures and higher ratings by MDs.  The histogram provides a visual representation of the overall distribution of blood pressure for all patients.  Github Repository: https://github.com/matthewluu2002/R-Programming.git