Posts

Showing posts from February, 2025

Module # 7 R Object: S3 vs. S4 assignment

Issaiah Jennings Module # 7 R Object: S3 vs. S4 assignment In this blog, I will walk through a practical example of using object-oriented systems (S3 and S4) in R. > # Step 1: Load and View the Dataset > data("mtcars")   > head(mtcars, 6)                      mpg cyl disp  hp drat    wt  qsec vs am gear carb Mazda RX4         21.0   6  160 110 3.90 2.620 16.46  0  1    4    4 Mazda RX4 Wag     21.0   6  160 110 3.90 2.875 17.02  0  1    4    4 Datsun 710        22.8   4  108  93 3.85 2.320 18.61  1  1    4    1 Hornet 4 Drive    21.4   6  258 110 3.08 3.215 19.44  1  0    3    1 Hornet Sportabout 18.7   8  360 175 3.15 3.440...

Module # 6 Doing math in R part 2

Issaiah Jennings Module # 6 Doing math in R part 2 In this code, I performed three matrix operations in R. First, I created two matrices, A and B , and used basic matrix arithmetic to compute their sum and difference. Next, I used the diag() function to generate a 4x4 diagonal matrix with specific values. Finally, I constructed a 5x5 matrix by initializing a diagonal of 3s and modifying the first row and column to match the required structure. This method illustrates simple and effective matrix manipulation techniques in R. > # 1. Define matrices A and B > A <- matrix(c(2,0,1,3), ncol=2) > B <- matrix(c(5,2,4,-1), ncol=2) > > # a) Matrix Addition > A_plus_B <- A + B > > # b) Matrix Subtraction > A_minus_B <- A - B > > # 2. Create a diagonal matrix with given values > diag_matrix <- diag(c(4,1,2,3)) > > # 3. Generate the specified 5x5 matrix > m <- diag(3, 5, 5) > m[1, 2:5] <- 1 # Set first row (except first elemen...

Module # 6 assignment

Image
Issaiah Jennings Module # 6 assignment I started by using the mtcars dataset to explore the distribution of cars based on their number of cylinders. To do this, I created two different visualizations: a pie chart and a bar chart. First, I calculated how many cars had 4, 6, and 8 cylinders using the table() function. Then, I created a pie chart to represent the proportions visually. I added colors (red, blue, and green) to make it clearer and included a title for context. Next, I created a bar chart using the same data. The bar chart is often easier to read since it allows for direct comparisons between categories. Like the pie chart, I added colors and labels to improve clarity. Both charts provide a quick look at the data, but the bar chart is more effective for comparing values, while the pie chart is useful for seeing proportions at a glance. This was a great way to test how different visualizations can present the same information in unique ways. # Load dataset data(mtcars) # Count...

Module # 5 Doing Math

Issaiah Jennings  Module # 5 Doing Math In this assignment, I worked with two matrices, A and B. Matrix A is a 10x10 square matrix, so I calculated its determinant. If the determinant was not zero, I found the inverse using the solve() function. If the determinant was zero, I returned a message saying the matrix is singular and doesn't have an inverse. Matrix B is a 10x100 matrix, which is not square, so it doesn't have a determinant or an inverse. I handled both cases by checking the conditions before trying to compute the inverse and printed appropriate messages. > # Define matrix A > A <- matrix(1:100, nrow=10) >  > # Define matrix B > B <- matrix(1:1000, nrow=10) >  > # Compute determinant of A > det_A <- det(A) >  > # Check if A is invertible (det(A) ≠ 0) > if (det_A != 0) { +   inv_A <- solve(A)  # Compute inverse of A + } else { +   inv_A <- "Matrix A is singular and does not have an in...

Module # 4 Programming structure in R

Image
The following data was collected by the local hospital. This data set contains 5 variables based on observation of 8 patients. In addition to the measurements of the patients checking in to the hospital that night, this data provides the patients' histories regarding the frequency of their visits to the hospital in the last 12 months.This data displays the measurement of blood pressure, first assessment by general doctor (bad=1, good =0) titled "first," the second assessment by external doctor (called "second"), and the last row provides the head of the emergency unit's decision regarding immediate care for the patient based on the values 0 or 1 (low = 0, high =1). The names of your variables are as follows: "Freq","bloodp","first”, " second”, ”finaldecision” > # Create vectors for each variable > Frequency <- c(0.6, 0.3, 0.4, 0.4, 0.2, 0.6, 0.3, 0.4, 0.9, 0.2) > BP <- c(103, 87, 32, 42, 59, 109, 78, 205, 135, 176...