Posts

Showing posts from October, 2025

Assignment #9 - Visualization in R – Base Graphics, Lattice, and ggplot2

Image
R code: GitHub link Generated plots:  Scatter plot:  Histogram: Conditional scatter plot (lattice): Scatter with linear trend (ggplot2): Discussion:  How do the syntax and workflow differ between base, lattice, and ggplot2? Base R is very simple and step-by-step, where you first call 'plot( )', and then begin to add what you want line by line, such as points, lines, or legends. With lattice, you establish the description of the plot once with a formula 'xyplot(y ~ x | group, data=df)', with optional formatting lines, and then it renders the plot from that. It is more rigid with edits and requires you to edit the actual code rather than additional lines. Finally, ggplot2 is built together, data + aesthetics + layers 'ggplot(df, aes(x, y, color=group)) + geom_point( ) + geom_smooth( )', therefore allowing it to be easily tweaked.  Which system gave you the most control or produced the most “publication‑quality” output with minimal code? I would say that ggplot2 pr...

Assignment #8: Input/Output, String Manipulation, and the plyr Package

Image
  R script:  GitHub link:  Assignment_08_Input_Output_String_Manipulation Outputs for each step:  Descriptions of each step: Import data :  I loaded the Assignment 6 dataset file using file.choose() so the file can be selected manually. It then ensures the data is made into a data frame with proper headers and types. Load plyr and compute mean of grade by sex : I installed and loaded in the package 'plyr', grouped the rows by 'Sex', then calculated the average 'Grade' to summarize the performance by gender. Write grouped means to text file :  I exported the summary to a tab-delimited "gender_mean.txt" file making the results easy to read. Filter names containing "i" : Using grepl("i", Name, ignore.case=TRUE), I selected only students whose names contained "i" or "I" to practice filtering. Export names only to a CSV : I saved the filtered names to "i_students.csv" to produce a compact output using the re...

Assignment #7 - Exploring R's Object Oriented System (S3 & S4)

Image
 R code and outputs:  Github repo link:  https://github.com/hannahcardenas4/r-programming-assignments/tree/main/R_Programming_Fall2025_Cardenas_Hannah/Assignment_07_Object_Oriented_Systems Questions: How can you tell whether an object uses S3 or S4? (Which functions inspect its class system?) To determine if an object uses S3 or S4, the first check can be done with the isS4( ) function. If it returns TRUE, then it is an S4 object; otherwise, it is likely an S3. Another check can be performed with the class(x) function to determine the labeling format. S3 classes are typically simple, lists, and data frames. S4 classes generally are more complex, with slots and data types.  How do you determine an object's underlying type (e.g., integer vs list)? To determine an object's underlying type, you can use the function typeof( ). An example output of the object's underlying type would be "list", "double", or "character". To specifically test for an int...

Assignment #6 - Matrix Operations and Construction

Image
 Full R code used for tasks 1-3: The printed output or matrices from each task: Summaries of each operation: 1. Matrix addition and subtraction: The "A + B" function adds the elements of matrices A and B, and the "A - B" function subtracts the elements of matrix B from A. Both of these functions result in a new matrix of the same size.  2. Create a diagonal matrix:  The "diag(c(4, 1, 2, 3))" function creates a 4x4 matrix with the indicated numbers along the diagonal and places zeros in each of the remaining positions.  3. Construct a custom 5x5 matrix: The "D <- diag(3, 5)" line creates a 5x5 matrix with the number 3 along the diagonal and zeros in the remaining positions. Then the "D[, 1] <- c(3, 2, 2, 2, 2)" line retains the first value, but replaces each value in column 1 to be the number 2. Finally, "D[1, 2:5] <- 1" creates the first row pattern to be (3, 1, 1, 1, 1), and completes the custom matrix.  GitHub link:...