Posts

Showing posts from March, 2026

Assignment #10: Building Your Own R Package

Github Link: https://github.com/rayhankhan-svg/Friedman I developed the framework for the Friedman R package for Module #10. I gained a better understanding of a R package's structure and the function of the DESCRIPTION file thanks to this assignment. R uses the machine-readable metadata found in the DESCRIPTION file to install, document, and verify the package. The package name, title, version, author details, description, dependencies, license, and additional optional elements like URL and BugReports are all included. My package's goal is to assist users in organizing, summarizing, and visualizing workplace and educational data in R. Students, novice analysts, and researchers looking for basic tools for data cleansing and producing understandable summaries and graphs are the target audience for my package. A function for cleaning datasets, a method for creating summary statistics, and a function for creating ggplot2 visualizations are some of the main features I intend to cre...

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

Image
Github Link: https://github.com/rayhankhan-svg/r-programming-assignments R Code:  data <- read.csv(file.choose(), stringsAsFactors = FALSE) head(data) str(data) data$rownames <- as.numeric(data$rownames) data$education <- as.numeric(data$education) plot(data$rownames, data$education,      main = "Base: Education by Observation",      xlab = "Observation",      ylab = "Education",      col = "blue") hist(data$education,      main = "Base: Distribution of Education",      xlab = "Education",      col = "lightgreen") library(lattice) xyplot(education ~ rownames | gender,        data = data,        main = "Lattice: Education by Observation and Gender") bwplot(education ~ job,        data = data,        main = "Lattice: Education by Job Type") library(ggplot2) ggplot(data, aes(x = rownames, ...

Module # 8 Input/Output, string manipulation and plyr package

Github Link:  https://github.com/rayhankhan-svg/r-programming-assignments R Code:  # Step 1: Import dataset x <- read.table(file.choose(), header = TRUE, sep = ",") # View dataset x # Step 2: Install/load plyr and calculate mean Grade by Sex install.packages("plyr") library(plyr) y <- ddply(x, "Sex", transform, Grade.Average = mean(Grade)) # View result y # Step 3: Write the mean result to a CSV-style file write.table(y, "Sorted_Average", sep = ",", row.names = FALSE) # Step 4: Filter names containing the letter i or I newx <- subset(x, grepl("[iI]", x$Name)) # View filtered dataset newx # Step 5: Write the filtered subset to a CSV-style file write.table(newx, "DataSubset", sep = ",", row.names = FALSE) Output:  > # Step 1: Import dataset > x <- read.table(file.choose(), header = TRUE, sep = ",") >  > # View dataset > x         Name Age    Sex Grade 1       Raul  25   Ma...

Module # 7 R Object: S3 vs. S4 assignment

Github Link:  https://github.com/rayhankhan-svg/r-programming-assignments R Code:  # Step 1: Load a dataset data(mtcars) head(mtcars, 6) # Step 2: Check if generic functions can be used on this dataset class(mtcars) typeof(mtcars) isS4(mtcars) # Generic functions examples summary(mtcars) plot(mtcars$mpg, mtcars$hp) # What is a generic function? mean # Step 3: Create an S3 example s3 <- list(name = "Myself", age = 29, GPA = 3.5) class(s3) <- "student" s3 class(s3) typeof(s3) isS4(s3) # Step 4: Create an S4 example setClass("student",          slots = list(            name = "character",            age  = "numeric",            GPA  = "numeric"          )) s4 <- new("student", name = "Myself", age = 29, GPA = 3.5) s4 class(s4) typeof(s4) isS4(s4) Output:  > # Step 1: Load a dataset > data(mtcars) > head(mtcars...