Posts

Showing posts from October, 2025

Module 9. Assignment

Image
  1.How does the syntax and workflow differ between base, lattice, and ggplot2? You call plot() and hist() in Base R and specify labels, colors, and other things by yourself.Lattice has a formula interface (y ~ x | group) that makes tiny multiples simple to construct without having to write  loops by hand.ggplot2 employs a layered syntax that is consistent and may be added to across plots.The layers include data, aesthetics, geoms, and facets. 2. Which system gave you the most control or produced the most “publication‑quality” output with minimal code? Layering (geom_point() + geom_smooth()) and consistent theming in ggplot2 provide professional pictures rapidly.Lattice is an excellent way to create conditioned views with very little code. Base is the quickest rapid inspections, but it requires more manual styling to look goodfor publishing. 3. Any challenges or surprises you encountered when switching between systems The mental model evolves every time:  Base is easy to ...

Assignment 8

Image
 I learned how to load data into R, summarize it, filter it, and save the results in different file types for this project.First, I set up my working location so that R could find files quickly and save them in a neat place. After that, I used read.table() to add the information to a data frame. This helped me learn how heads and divisions work when reading real data. Next, I used the ddply() method and the plyr package to find the average grade and age for each gender. This taught me how to do grouped reports in R.  Lastly, I used the subset() and grepl() methods to practice filtering data. I got all the student names that started with "i" and saved both the names-only and full filtered results. By following these steps, I learned how to use R to automatically clean data, analyze it, and send it to a file. These are important skills for working with datasets quickly.  # R Code  setwd("C:/Users/shanz/OneDrive/Documents/Assigment 6") x <- read.table("Assignme...

Module 7. Assignment

Image
This week, I studied Object-Oriented Programming (OOP) in R and discovered that R perceives all entities as objects, including integers, vectors, data frames, and functions. The talk addressed two main systems used in R: S3 and S4. S3 is the preliminary, more accessible way that allows for the rapid addition of a class to a list and the creation of custom print methods. S4 is the more recent and systematically structured framework that has inherent validation and explicit class definitions with slots. We further examined the use of common methods such as summary(), print(), and plot() to see their distinct functionalities across different object kinds. Ultimately, I was able to create my own S3 and S4 objects, implement fundamental methods, and understand how R determines which function version to use, a process known as method dispatch. # Download Data for Mtcar data("mtcars") # Show the first few rows head(mtcars) # Describe its structure str(mtcars) # Test Generic Function...

Module 6 – Linear Algebra in R (Part 2)

Image
  # 1. Matrix Addition & Subtraction A <- matrix(c(2, 0, 1, 3), ncol = 2) B <- matrix(c(5, 2, 4, -1), ncol = 2) # Addition A_plus_B <- A + B A_plus_B # Subtraction A_minus_B <- A - B A_minus_B Explanation : Matrix addition and subtraction work element-by-element on matrices of the same size, combining or contrasting values at the same positions. This is useful for quickly aggregating or comparing structured numeric data # 2.Create a Diagonal Matrix D <- diag(c(4, 1, 2, 3)) D Explanation :  diag() places the supplied numbers along the main diagonal and fills all other entries with zeros. Diagonal matrices are commonly used for identity/scaling operations and as building blocks in linear algebra. # 3.Construct a Custom 5 × 5 Matrix M <- diag(3, 5, 5)           M[1, 2:5] <- 1               M[2:5, 1] <- 2     M Explanation :  started with a diagonal of 3’s and then...