Posts

Showing posts from October, 2025

Module 9. visualization systems in R

Image
  How does the syntax and workflow differ between base, lattice, and ggplot2? Base R graphics follow a “build-as-you-go” approach, where you start with a simple plot and add elements like lines or text step by step. Lattice graphics use a formula interface and require you to specify everything in one function call, producing multi-panel (conditioned) plots automatically but with less post-hoc flexibility. In contrast, ggplot2 uses the “grammar of graphics,” layering data, aesthetics, and geoms with a clear and consistent syntax. Which system gave you the most control or produced the most “publication‑quality” output with minimal code? ggplot2 produced the most publication-quality visuals with the least effort. Its default styling is clean and modern, legends are automatically generated, and themes allow easy customization for consistent, professional output. It also provided more outlook on the data as a whole, compared to the other systems.  Any challenges or surprises y...

Module 8. Assignment CSV files

Image
  (please click images for higher clarity) The images above showcase file‑write operations succeeded and the R code.  The first step imports the data without commas, from the dataset.txt file. It then creates a summarized table that shows the average grade for males and females. The resulting data frame, gender_mean, is then written to a tab-delimited text file named gender_mean.txt for reference or sharing. The second step filters the data to find all students whose names contain the letter “i” or “I,” using the grepl() function. A smaller data frame, i_students, is created from these matching rows and saved to a csv file. The final step produces a new csv file, created including all original columns, for just the names including the letter "I". This is the final document for this project, creating a new data set containing just those names. 

Module 7. S3 and S4 object systems

Reflection: You can check whether an object is an S4 object by using isS4(object), which returns TRUE for S4 and FALSE otherwise. For S3 objects, you can look at their class with class(object) and see if they were created by simply assigning a class attribute. To see the underlying data type of an object, you can use the typeof() function. It shows the low-level storage type, such as “integer,” “double,” “list,” or “character.” You can also use str(object) for a more detailed look at the object’s internal structure and types of its components. A generic function in R is a special kind of function designed to work flexibly with different types of objects. It performs method dispatch, meaning it automatically calls a version of the function that matches the class of the object you provide. This allows R to adapt behavior to the data type, promoting cleaner and more intuitive code. Examples include print(), summary(), and plot(), which behave differently for data frames, lists, o...

Module 6. Assignment- Creating basic and diagonal matrices

Image
  Adding two matrices combines their entries element by element, while subtraction takes the difference the same way. This makes it easy to see how corresponding values from  A and B interact. The diag() function builds a matrix with the given numbers along the main diagonal. All off-diagonal entries are set to zero automatically. Combining a special first column with a diagonal block using  cbind()  and  rbind() . This shows how smaller pieces can be stacked together to form a structured matrix. R code pasted: #1. Matrix Addition & Subtraction # Define matrices 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 #2. Build 4x4 diagonal matrix D <- diag(c(4, 1, 2, 3)) D #3. Construct a Custom 5×5 Matrix first_col <- c(3, 2, 2, 2, 2) diag_block <- diag(3, 4) #Bind them together M <- cbind(first_col, rbind(rep(1, 4), diag_block)) M