Posts

Showing posts from March, 2026

Assignment 10

Image
 For this assignment, I created my first R package called Friedman , which is designed to provide simple tools for data visualization and basic analysis. The goal of this package is to make working with data easier, especially for students or beginners who may find R overwhelming at first. Instead of writing long lines of code, users can quickly generate visuals and explore datasets using simple functions. One of the main functions included is plot_summary() , which creates a scatter plot using ggplot2 with minimal input. Overall, the package focuses on simplicity, efficiency, and making data exploration more accessible. The DESCRIPTION file plays an important role in defining the structure and purpose of the package. I included key fields such as the package name, version (0.0.0.9000 for development), and a short description explaining what the package does. I listed myself as both the author and creator using the Authors@R field, and included dependencies like ggplot2 and dplyr ...

Assignment #9

Image
For this assignment, I used the mtcars dataset to compare three visualization systems in R: base graphics, lattice, and ggplot2. Using base R, I created a scatter plot of MPG vs horsepower and a histogram of MPG, which were simple and quick to generate using functions like plot() and hist() . Next, I used the lattice package to create a conditional scatter plot and a boxplot grouped by the number of cylinders, which made it easier to compare patterns across categories. Finally, with ggplot2, I created a scatter plot with a regression line and a faceted histogram, allowing for a more structured and layered approach to visualization. The main difference between the three systems is how they handle syntax and workflow. Base R is the most straightforward but can become limited when creating more complex visuals. Lattice is useful for grouped data but has less intuitive syntax. ggplot2, while slightly more complex at first, provided the most control and produced the most polished, profes...

Assignment #8

Image
  For this assignment, I worked with a dataset that included the variables Name, Age, Sex, and Grade. Assignment 6 Dataset The first step was importing the dataset into R using the read.table() function. This allowed the data from the text file to be loaded into R so it could be analyzed. Next, I used the plyr package to calculate the mean grade grouped by Sex. The ddply() function split the dataset by gender and calculated the average grade for each group. After generating the results, I saved the output to a file using the write.table() function. The next step was filtering the dataset for names that contain the letter “i.” I used the subset() function with grepl() to search for the letter in the Name column. This created a new dataset containing only those students. Finally, I exported the filtered dataset to a CSV file. This assignment showed how R can import data, perform grouped calculations, filter text values, and export results to files. macauleywilson/r-programming...

Assignment #7

Image
For this assignment, I used the built-in mtcars dataset in R. I loaded it using data("mtcars") and checked the structure with str(mtcars) . The class shows it is a data.frame , and typeof(mtcars) shows its base type is actually a list. When I ran isS4(mtcars) , it returned FALSE, meaning it is not an S4 object. So mtcars is an S3 object. A generic function is a function that works differently depending on the object’s class. Examples are summary() , print() , and plot() . When I run summary(mtcars) , R automatically uses the method made for data frames. That is method dispatch. To create an S3 example, I made a list with name, age, and GPA, then assigned it a class using class(student_s3) <- "student" . I also created a custom print method. This shows how simple and flexible S3 is. For S4, I used setClass() to formally define a class with slots and their data types. Then I created an object using new() . S4 is stricter because you must define everything firs...