Posts

Showing posts from March, 2024

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