Posts

Final Project

  Recipe Analyzer Package For my final project, I decided to create a Recipe Analyzer Package. The functions included in my package are designed to help users analyze nutritional information, scale recipes based on servings, and generate shopping lists from recipes. Description:  Package: RecipeAnalyzer Type: Package Title: Analyze and Scale Recipes Version: 1.0 Date: 2024-04-25 Author: Elisa Hardie Maintainer: ehardie@usf.edu Description: Provides functions to analyze nutritional content, scale recipes, and generate shopping lists. License: GNU General Public License Imports:   Depends: R (>= 4.0) The first function, `analyze_nutrition`, calculates the nutritional information for a given recipe. This includes total calories, fat, carbohydrates, and protein. #Analyze Nutrition function (with example values) analyze_nutrition <- function(recipe) {      # Example nutritional values per unit (could be expanded to use a real database)   nutrition_dat...

Module #11 Assignment

 3/24/34 This week, we are tasked with debugging R code.  First, I copied the bugged code into RStudio in order to see the error it returns. I also installed and loaded the "outliers" package. I also ran debug(tukey_multiple): > debug(tukey_multiple) > tukey_multiple(x) debugging in: tukey_multiple(x) debug at #1: { outliers <- array(TRUE, dim = dim(x)) for (j in 1:ncol(x)) { outliers[, j] <- outliers[, j] && tukey.outlier(x[, j]) } outlier.vec <- vector(length = nrow(x)) for (i in 1:nrow(x)) { outlier.vec[i] <- all(outliers[i, ]) } return(outlier.vec) } Browse[2]> After further investigation, I found that the && operator is used when instead, & operator should be used. && only evaluates the second expression if the first one is true.

Module #9

Image
 3/10/2024 For this assignment, I chose a csv file containing data on cigarette consumption by state.  I first read in the data:  data <- read.csv ( "C: \\ Users \\ elisa_pazp940 \\ Downloads \\ CigarettesB.csv" ) head (data) ##   rownames   packs   price  income ## 1       AL 4.96213 0.20487 4.64039 ## 2       AZ 4.66312 0.16640 4.68389 ## 3       AR 5.10709 0.23406 4.59435 ## 4       CA 4.50449 0.36399 4.88147 ## 5       CT 4.66983 0.32149 5.09472 ## 6       DE 5.04705 0.21929 4.87087 Then created a bar plot that shows cigarette consumption across different states: # Bar plot: Cigarette packs consumption across different states barplot (data $ packs, names.arg = rownames (data), las = 2 , col = "skyblue" ,      ...

Module #8 Assignment

 For this assignment, I imported a data set into R. I converted this dataset into a dataframe with only students whose name contains the letter 'i'. Finally, I converted the data to a csv file. Here is my code: file_path <- "C:/Users/elisa_pazp940/Downloads/Assignment 6 Dataset.txt" data <- read.table(file_path, header = TRUE, sep = ",") install.packages('plyr') library(plyr) sex = data$Sex mean(sex) y = ddply(data, "Sex", transform, Grade.Average=mean(Grade)) y write.table(y, "Sorted_Average") write.table(y, "Sorted_Average", sep=",") newdata = subset(data, grepl("[iI]", data$Name)) write.table(newdata, "DataSubset", sep = ",") newdata

Module #7 Assignment

 For this assignment, I used the popular mtcars dataset for my analysis. My code is as follows: data("mtcars") head(mtcars) list(mtcars) #we can create generic functions for mtcars such as functions to find the  #mean or a function to create plots such as bar or scatter plots. #S3 method class(mtcars) summary.mtcars <- function(object, ...) {   summary(object) } summary(mtcars) #S3 methods can be applied #s4 method setClass("mtcarsClass", contains = "data.frame") mtcars_s4 <- new("mtcarsClass", mtcars) mtcars_s4 #S4 methods can be applied How do you tell what OO system (S3 vs. S4) an object is associated with? You can use the functions isS3method() and is4() How do you determine the base type (like integer or list) of an object? You can use the class function What is a generic function? A function that behaves according to the class it is applied to. What are the main differences between S3 and S4? S4 is more complex and structured than S3....

Module #6

 For this assignment, I created four matrices based on the given A and B data. Here are my results: > A <- matrix(c(2, 0, 1, 3), ncol = 2) > B <- matrix(c(5, 2, 4, -1), ncol = 2) > Matrix_one <- A + B > Matrix_one [,1] [,2] [1,] 7 5 [2,] 2 2 > Matrix_two <- A - B > Matrix_two [,1] [,2] [1,] -3 -3 [2,] -2 4 > diag_matrix <- diag(c(4, 1, 2, 3)) > diag_matrix [,1] [,2] [,3] [,4] [1,] 4 0 0 0 [2,] 0 1 0 0 [3,] 0 0 2 0 [4,] 0 0 0 3 > final_matrix <- diag(3, 5) > final_matrix [,1] [,2] [,3] [,4] [,5] [1,] 3 0 0 0 0 [2,] 0 3 0 0 0 [3,] 0 0 3 0 0 [4,] 0 0 0 3 0 [5,] 0 0 0 0 3 >

Module #5

 2/11/24 For this assignment, I defined the matrices A and B, then attempted to find their inverse and determinant using the solve() and det() functions. I got these errors, which I believe is because is singular and therefore not invertible.  > A <- matrix(1:100, nrow=10) > B <- matrix(1:1000, nrow=10) > solve(A) Error in solve.default(A) : Lapack routine dgesv: system is exactly singular: U[6,6] = 0 > det(A) [1] 0 > A <- matrix(1:100, nrow=10) > B <- matrix(1:1000, nrow=10) > solve(A) Error in solve.default(A) : Lapack routine dgesv: system is exactly singular: U[6,6] = 0 > det(A) [1] 0 > solve(B) Error in solve.default(B) : 'a' (10 x 100) must be square > det(B) Error in determinant.matrix(x, logarithm = TRUE, ...) : 'x' must be a square matrix > A <- matrix(1:100, nrow=10) > B <- matrix(1:1000, nrow=10) > solve(A) Error in solve.default(A) : Lapack routine dgesv: system is exactly singular: U[6,6] ...