Posts

Showing posts from October, 2025

Module 9: Visualization in R – Base Graphics, Lattice, and ggplot2

Image
GitHub Repository:  AustinTCurtis/r-programming-assignments Choose one dataset from the  Rdatasets collection: data("iris", package = "datasets") head(iris) df <- iris Base R Graphics Create at least two plots using base R functions. # Scatterplot: species_cols <- c(setosa = "steelblue", versicolor = "orange", virginica = "forestgreen") plot(df$Sepal.Length, df$Sepal.Width,      main = "Base: Sepal.Width vs Sepal.Length",      xlab = "Sepal Length", ylab = "Sepal Width",      col = species_cols[df$Species], pch = 19) legend("topright", legend = levels(df$Species),        col = species_cols, pch = 19, bty = "n") # Histogram: hist(df$Petal.Length,      main = "Base: Distribution of Petal Length",      xlab = "Petal Length") Lattice Graphics Use the lattice package to produce conditioned or multivariate plots. # Lattice Graphics library(lattice) # Conditional scatt...

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

Image
GitHub Repository:  AustinTCurtis/r-programming-assignments In this post, I’ll walk through each line of code I used for the  Assignment 8 , explaining what every step does and why it’s important. The goal of this assignment was to import a dataset, analyze grades by gender, filter specific names, and export the results into different file formats using R Studio. Step 1:  Importing the Dataset student6 <- read.csv(file.choose(), header = TRUE, stringsAsFactors = FALSE) This line opens an interactive file-chooser window so I can select my dataset (a CSV file). header = TRUE tells R that the first row contains the column names (Name, Age, Sex, Grade). stringsAsFactors = FALSE ensures that text columns (like Name or Sex) stay as character strings rather than being automatically converted to factors. Step 2:  Checking the Data head(student6) str(student6) head(student6) displays the first few rows so I can preview the dataset. str(student6) shows each column’s data ty...

Module 7: Exploring R’s Object Oriented Systems (S3 & S4)

GITHUB REPOSITORY:   r-programming-assignments/Assignment_07.R at main · AustinTCurtis/r-programming-assignments   Choose or Download Data Load an existing dataset (e.g.,  data("mtcars") ) or download/create your own. Show the first few rows with  head()  and describe its structure with  str() . R CODE: # Built-in dataset data("mtcars") # Peek at the data head(mtcars) str(mtcars) Test Generic Functions Pick one or more base generic functions (e.g.,  print() ,  summary() ,  plot() ). Apply them to your dataset or an object derived from it. If a generic does *not* dispatch on your object, explain *why* (e.g., no method defined for that class). R CODE: # These are all generics that dispatch methods based on class print(mtcars)          # Uses print.data.frame summary(mtcars)        # Uses summary.data.frame # Derived an object fit <- lm(mpg ~ hp + wt, data = mtcars) class(fit) summary(fit)  ...

Module 6: Matrix Operations and Construction

GitHub Repository:  r-programming-assignments/Assignment_06.R at main · AustinTCurtis/r-programming-assignments Part I — Matrix Addition & Subtraction In this section, I’m creating two matrices A and Busing the matrix() function. Both matrices have 2 columns. After defining them, I perform matrix addition (A+B)  and matrix subtraction (A-B)  These operations are performed elementwise, meaning R adds or subtracts each corresponding element from the same position in both matrices. R Code: # Define two 2x2 matrices A and B A <- matrix(c(2, 0, 1, 3), ncol = 2) B <- matrix(c(5, 2, 4, -1), ncol = 2) # Display A and B A B # Matrix addition A_plus_B <- A + B A_plus_B # Matrix subtraction A_minus_B <- A - B A_minus_B Part II — Creating a Diagonal Matrix Here, I use the diag() function to create a 4×4 diagonal matrix called D. A diagonal matrix has non-zero values only along its main diagonal (from top left to bottom right), with zeros everywhere else. I specify th...