Posts

Assignment 10

Image
  Assignment 10: Building Your Own R Package Objectives The Premitha package is an R package designed to simplify common data analysis and visualization tasks. It is intended for students, researchers, and analysts who want to quickly explore datasets, summarize numeric variables, and create basic plots without writing repetitive code. R Code # Step 0: Install tools install.packages("devtools") install.packages("roxygen2") library(devtools) library(roxygen2) # Step 1: Create your package setwd("/Users/premithapagadala/Documents/R_Programming_Fall2025_Pagadala_Premitha/Assignments/Assignment_10_Create_Package") create("Premitha") setwd("Premitha") #working directory inside your package # Step 2: Write DESCRIPTION file desc_lines <- ' Package: Premitha Title: Simple Tools for Streamlined Data Analysis Version: 0.0.0.9000 Authors@R:      person("Premitha", "Pagadala",             email = "premithapagadala@g...

Assignment 9

Image
  Assignment 9: Visualization in R – Base Graphics, Lattice, and ggplot2 Objectives Compare three major visualization systems in R: Base graphics , Lattice , and ggplot2 . Apply all three to the same dataset to observe syntactic , conceptual , and visual differences . Produce clear, reproducible code and interpret key findings. Dataset Overview For this assignment, I used the Breast Cancer Wisconsin Diagnostic dataset ( brca ) from the dslabs package — a common bioinformatics dataset used to classify tumor samples as Benign (B) or Malignant (M) based on cell nucleus measurements. This dataset contains features computed from breast mass cell nuclei. brca$y = Diagnosis (Benign or Malignant) brca$x = 30 numeric features describing cell characteristics Load and explore the data # Load libraries and dataset install.packages("dslabs") library(dslabs) data("brca") # 'brca$y' contains the diagnosis (Benign/ Malignant) # 'brca$x' is a matrix of 30...

Assignment 8

Image
  Assignment 8 — Input/Output, String Manipulation, and the plyr Package Objectives This assignment focused on using R to handle input/output operations , perform data summarization using the plyr package, and apply string manipulation techniques. By completing this exercise, I learned how to import data files, compute grouped statistics, filter data based on character patterns, and export processed results in multiple formats. R Code # Step 1: Import dataset into R # Choose file interactively or specify directly student6 <- read.table(   file.choose(),       header = TRUE,   sep = ",",   stringsAsFactors = FALSE ) # Step 2: Install and load plyr package install.packages("plyr") library(plyr) # Compute mean Grade by Sex gender_mean <- ddply(   student6,   "Sex",   summarise,   GradeAverage = mean(Grade, na.rm = TRUE) ) # Step 3: Write the grouped means to a text file write.table(   gender_mean,   file = "gend...

Assignment 7

Image
  Assignment 7: Exploring R’s Object-Oriented Systems (S3 & S4) In this assignment, I explored R's object-oriented systems, focusing on S3 and S4 classes. The objective was to understand how R dispatches generic functions based on object class and to practice creating and manipulating S3 and S4 objects. Objectives The goal of this assignment was to explore R’s two primary object-oriented systems— S3 and S4 —and understand how generic functions work with different object types. Specifically, we: Selected and inspected a dataset. Tested base R generic functions. Created custom S3 and S4 objects. Compared the behavior and structure of both systems. R Code Step 1: Loading the Dataset We begin by using one of R’s built-in datasets, PlantGrowth , which measures the effect of different treatments on plant growth. # Load dataset data("PlantGrowth") head(PlantGrowth) # Describe structure str(PlantGrowth) Output:  Step 2: Test Generic Functions # Summarize datas...

Assignment 6

Image
  Assignment 6: Matrix Operations and Construction In this assignment,  I practiced creating and manipulating matrices in R. The goal was to strengthen my understanding of how R handles matrix operations such as addition, subtraction, diagonal construction, and combining blocks of matrices to form structured arrays. R Code 🔹 Task 1: Matrix Addition & Subtraction # Task 1: define A and B A <- matrix(c(2, 0, 1, 3), ncol = 2) B <- matrix(c(5, 2, 4, -1), ncol = 2) # Addition A_plus_B <- A + B print("A + B:") print(A_plus_B) # Subtraction A_minus_B <- A - B print("A - B:") print(A_minus_B) 🔹 Task 2: Create a Diagonal Matrix # Task 2: Create a Diagonal Matrix D <- diag(c(4, 1, 2, 3)) print("Diagonal Matrix D:") print(D) 🔹 Task 3: Construct a Custom 5×5 Matrix # Task 3: Construct a Custom 5x5 Matrix # Step 1: create the first row row1 <- c(3, 1, 1, 1, 1) # Step 2: create the remaining rows: # - first column all 2’s (rows 2–5) # - diagonal...

Assignment 5

Image
Assignment 5: Matrix Algebra in R For this assignment, I explored how to create and inspect matrices in R, how to compute matrix inverses and determinants, and how to handle errors when working with non-square matrices. I also reflected on issues of numeric stability and performance that arise in matrix algebra computations. R Code # 1. Create the matrices A <- matrix(1:100, nrow = 10) B <- matrix(1:1000, nrow = 10) # 2. Inspect dimensions dimA <- dim(A) # should be 10 × 10 dimB <- dim(B) # should be 10 × 100 print("Dimensions of A:") print(dimA) print("Dimensions of B:") print(dimB) # 3. Compute inverse and determinant for A invA <- solve(A) detA <- det(A) print("Inverse of A:") print(invA) print("Determinant of A:") print(detA) # 4. Handle non-square matrix B with tryCatch invB <- tryCatch(solve(B), error = function(e) e) detB <- tryCatch(det(B), error = function(e) e) print("Inverse of B attempt:") print...