From aa506711ae5866037d2d37b015d55ac0dc02e38f Mon Sep 17 00:00:00 2001 From: Marlee Shaffer Date: Fri, 29 Oct 2021 09:57:31 -0400 Subject: [PATCH 1/8] Added comments to outline tasks --- Ex7Script.R | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 Ex7Script.R diff --git a/Ex7Script.R b/Ex7Script.R new file mode 100644 index 0000000..9fbbeb6 --- /dev/null +++ b/Ex7Script.R @@ -0,0 +1,3 @@ +###Exercise 7 Script +###Marlee Shaffer + From f5e7c50d60208e199ab1d6b7a32db3cb847a2ebd Mon Sep 17 00:00:00 2001 From: Marlee Shaffer Date: Fri, 29 Oct 2021 10:13:06 -0400 Subject: [PATCH 2/8] Adds code to create a csv for the species setosa --- Ex7Script.R | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/Ex7Script.R b/Ex7Script.R index 9fbbeb6..9141eaa 100644 --- a/Ex7Script.R +++ b/Ex7Script.R @@ -1,3 +1,23 @@ ###Exercise 7 Script ###Marlee Shaffer +setwd("~/Desktop/Biocomp_tutorial9") +iris<-read.csv("iris.csv") + +##Part 1: Replicate the functionality fo the head function in bash + + + +#Part 2: Use iris.csv to: + +#Print the last 2 rows and the last two columns to the R terminal + +#Get the number of observations for each species in the data set + +#Get rows with Sepal.Width > 3.5 +rowcount<- funtion(x,y,z){width<- (x[y>z,])return(width)} +row(iris, iris$Sepal.Width, 3.5) + +#Write the data for species setosa to a comma-deliminated file named 'setosa.csv' + +#Calculate the mean, minimum, and maximum of Petal.Length for observations from virginica \ No newline at end of file From 30393ec66c9c8582c4d19cebaf3733cc914033ad Mon Sep 17 00:00:00 2001 From: Marlee Shaffer Date: Fri, 29 Oct 2021 10:16:04 -0400 Subject: [PATCH 3/8] This commit creates the code to calculate the number of obersations for each species --- Ex7Script.R | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Ex7Script.R b/Ex7Script.R index 9141eaa..7d5195e 100644 --- a/Ex7Script.R +++ b/Ex7Script.R @@ -13,11 +13,14 @@ iris<-read.csv("iris.csv") #Print the last 2 rows and the last two columns to the R terminal #Get the number of observations for each species in the data set +sum(iris[,5]=="virginica") +sum(iris[,5]=="setosa") +sum(iris[,5]=="versicolor") #Get rows with Sepal.Width > 3.5 -rowcount<- funtion(x,y,z){width<- (x[y>z,])return(width)} -row(iris, iris$Sepal.Width, 3.5) #Write the data for species setosa to a comma-deliminated file named 'setosa.csv' +setosa<-(iris[iris $"Species"=="setosa",]) +write.csv(setosa, 'setosa.csv') #Calculate the mean, minimum, and maximum of Petal.Length for observations from virginica \ No newline at end of file From c19f0d790ff2a148952535773748e7eb5999aea8 Mon Sep 17 00:00:00 2001 From: Marlee Shaffer Date: Fri, 29 Oct 2021 11:56:40 -0400 Subject: [PATCH 4/8] Completed part 1, added variables to make it easier to follow --- Ex7Script.R | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/Ex7Script.R b/Ex7Script.R index 7d5195e..b2b6213 100644 --- a/Ex7Script.R +++ b/Ex7Script.R @@ -1,26 +1,41 @@ ###Exercise 7 Script ###Marlee Shaffer -setwd("~/Desktop/Biocomp_tutorial9") -iris<-read.csv("iris.csv") - ##Part 1: Replicate the functionality fo the head function in bash +headR<-function(filename,linenum){ + file<-read.csv(filename) + return(file[1:linenum,]) +} - +#To check to make sure the newly developed function works properly, I used the wages.csv to pull the first 16 rows. +headR("wages.csv", 16) #Part 2: Use iris.csv to: +iris<-read.csv("iris.csv") #Print the last 2 rows and the last two columns to the R terminal +T<-tail(iris[,4:5],2) +print(T) #Get the number of observations for each species in the data set -sum(iris[,5]=="virginica") -sum(iris[,5]=="setosa") -sum(iris[,5]=="versicolor") +X<-sum(iris[,5]=="virginica") +Y<-sum(iris[,5]=="setosa") +Z<-sum(iris[,5]=="versicolor") +c("Virginica:", X, "Setosa:", Y, "Versicolor:", Z) #Get rows with Sepal.Width > 3.5 +sepal<-(iris[iris$"Sepal.Width">3.5,]) +print(sepal) #Write the data for species setosa to a comma-deliminated file named 'setosa.csv' setosa<-(iris[iris $"Species"=="setosa",]) write.csv(setosa, 'setosa.csv') -#Calculate the mean, minimum, and maximum of Petal.Length for observations from virginica \ No newline at end of file +#Calculate the mean, minimum, and maximum of Petal.Length for observations from virginica +vir<-(iris[iris$"Species"=="virginica",]) +head(vir) +M<-mean(iris[iris$"Species"=="virignica","Petal.Length"]) +head(M) +vir[["Petal.Width"]]) +min(vir[["Petal.Width"]]) +max(vir[["Petal.Width"]]) From 4546bcbc27d9befbe9239205c623af0ca44ddcc6 Mon Sep 17 00:00:00 2001 From: Marlee Shaffer Date: Sun, 31 Oct 2021 11:18:57 -0400 Subject: [PATCH 5/8] Adds code to calculate the mean, min, and max petal length --- Ex7Script.R | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/Ex7Script.R b/Ex7Script.R index b2b6213..17a1cc1 100644 --- a/Ex7Script.R +++ b/Ex7Script.R @@ -21,21 +21,22 @@ print(T) X<-sum(iris[,5]=="virginica") Y<-sum(iris[,5]=="setosa") Z<-sum(iris[,5]=="versicolor") -c("Virginica:", X, "Setosa:", Y, "Versicolor:", Z) +cat(c("Virginica:", X, "Setosa:", Y, "Versicolor:", Z)) #Get rows with Sepal.Width > 3.5 -sepal<-(iris[iris$"Sepal.Width">3.5,]) +sepal<-(iris[iris$Sepal.Width>3.5,]) print(sepal) #Write the data for species setosa to a comma-deliminated file named 'setosa.csv' -setosa<-(iris[iris $"Species"=="setosa",]) +setosa<-(iris[iris$Species=="setosa",]) write.csv(setosa, 'setosa.csv') #Calculate the mean, minimum, and maximum of Petal.Length for observations from virginica -vir<-(iris[iris$"Species"=="virginica",]) -head(vir) -M<-mean(iris[iris$"Species"=="virignica","Petal.Length"]) -head(M) -vir[["Petal.Width"]]) -min(vir[["Petal.Width"]]) -max(vir[["Petal.Width"]]) +df = iris +Mean<-mean(df$Petal.Length) +Min<-min(df$Petal.Length) +Max<-max(df$Petal.Length) +cat(c("Mean Petal Length:", Mean, + "Minimum Petal Length:", Min, + "Maximum Petal Length:", Max)) + From f17bac9917209695b73d4d2ed75a28b1152c5ddc Mon Sep 17 00:00:00 2001 From: Marlee Shaffer Date: Sun, 31 Oct 2021 11:32:06 -0400 Subject: [PATCH 6/8] Fixes print function to look better when it is output --- Ex7Script.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Ex7Script.R b/Ex7Script.R index 17a1cc1..e2f4572 100644 --- a/Ex7Script.R +++ b/Ex7Script.R @@ -15,7 +15,7 @@ iris<-read.csv("iris.csv") #Print the last 2 rows and the last two columns to the R terminal T<-tail(iris[,4:5],2) -print(T) +print(as.data.frame(T),row.names=FALSE) #Get the number of observations for each species in the data set X<-sum(iris[,5]=="virginica") From bb330492b04767364898176908a9edf2075329d7 Mon Sep 17 00:00:00 2001 From: Marlee Shaffer Date: Sun, 31 Oct 2021 11:38:36 -0400 Subject: [PATCH 7/8] Creates a better output for species and observations --- Ex7Script.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Ex7Script.R b/Ex7Script.R index e2f4572..79b8136 100644 --- a/Ex7Script.R +++ b/Ex7Script.R @@ -21,7 +21,7 @@ print(as.data.frame(T),row.names=FALSE) X<-sum(iris[,5]=="virginica") Y<-sum(iris[,5]=="setosa") Z<-sum(iris[,5]=="versicolor") -cat(c("Virginica:", X, "Setosa:", Y, "Versicolor:", Z)) +data.frame(Species=c("Virginica:", "Setosa:", "Versicolor:"),Observations=c(X, Y, Z)) #Get rows with Sepal.Width > 3.5 sepal<-(iris[iris$Sepal.Width>3.5,]) From 28a8196c5a2c417132cc1aa0d5c93fd644748f06 Mon Sep 17 00:00:00 2001 From: Marlee Shaffer Date: Sun, 31 Oct 2021 11:47:10 -0400 Subject: [PATCH 8/8] Better output for measurement mean, min, and max. --- Ex7Script.R | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/Ex7Script.R b/Ex7Script.R index 79b8136..7ac85cd 100644 --- a/Ex7Script.R +++ b/Ex7Script.R @@ -27,7 +27,7 @@ data.frame(Species=c("Virginica:", "Setosa:", "Versicolor:"),Observations=c(X, Y sepal<-(iris[iris$Sepal.Width>3.5,]) print(sepal) -#Write the data for species setosa to a comma-deliminated file named 'setosa.csv' +#Write the data for species setosa to a comma-delimited file named 'setosa.csv' setosa<-(iris[iris$Species=="setosa",]) write.csv(setosa, 'setosa.csv') @@ -36,7 +36,5 @@ df = iris Mean<-mean(df$Petal.Length) Min<-min(df$Petal.Length) Max<-max(df$Petal.Length) -cat(c("Mean Petal Length:", Mean, - "Minimum Petal Length:", Min, - "Maximum Petal Length:", Max)) +data.frame(Measurement=c("Mean Petal Length", "Minimum Petal Length", "Maximum Petal Length"),Value=c(Mean,Min,Max))