From ec376efaa213f4416f31e6c31ce220a818dc85a3 Mon Sep 17 00:00:00 2001 From: selidris <92063773+selidris@users.noreply.github.com> Date: Thu, 4 Nov 2021 20:30:01 -0400 Subject: [PATCH 1/3] Add files via upload --- Exercise7.R | 39 +++++++++++++++++++++++++++++++++++++++ setosa.csv | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 90 insertions(+) create mode 100644 Exercise7.R create mode 100644 setosa.csv diff --git a/Exercise7.R b/Exercise7.R new file mode 100644 index 0000000..9c583a2 --- /dev/null +++ b/Exercise7.R @@ -0,0 +1,39 @@ + +#Exercise 7 problem 1 + +#set working directory +setwd("~/Desktop/Biocomp_tutorial9-main") + +#define wages variable with wages.csv file and define lines variable with number of lines you want to return +wages<-read.table("wages.csv", header=TRUE, sep=",") +lines=5 + +fivelines<-wages[1:lines, ] +fivelines + +#Exercise 7 problem 2 + +iris<-read.table("iris.csv",header=TRUE,sep=",") + +#print the last 2 rows in the last 2 columns to the R terminal +iris[149:150,4:5] + +#get the number of observations for each species included in the data set +sumspecies<-iris[order(iris$Species, decreasing=TRUE),] +sum(sumspecies$Species=="virginica") +sum(sumspecies$Species=="versicolor") +sum(sumspecies$Species=="setosa") + +#get rows with Sepal.Width > 3.5 +sw<-(iris[iris$Sepal.Width>3.5,]) +print(sw) + +#write the data for the species setosa to a comma-delimited file names ‘setosa.csv’ +setosa<-subset(iris, Species=="setosa") +write.csv(setosa, file="setosa.csv", row.names=FALSE) + +#calculate the mean, minimum, and maximum of Petal.Length for observations from virginica +v=iris[iris$Species=="virginica",] +mean(v$Petal.Length) +max(v$Petal.Length) +min(v$Petal.Length) \ No newline at end of file diff --git a/setosa.csv b/setosa.csv new file mode 100644 index 0000000..2f03ff3 --- /dev/null +++ b/setosa.csv @@ -0,0 +1,51 @@ +"Sepal.Length","Sepal.Width","Petal.Length","Petal.Width","Species" +5.1,3.5,1.4,0.2,"setosa" +4.9,3,1.4,0.2,"setosa" +4.7,3.2,1.3,0.2,"setosa" +4.6,3.1,1.5,0.2,"setosa" +5,3.6,1.4,0.2,"setosa" +5.4,3.9,1.7,0.4,"setosa" +4.6,3.4,1.4,0.3,"setosa" +5,3.4,1.5,0.2,"setosa" +4.4,2.9,1.4,0.2,"setosa" +4.9,3.1,1.5,0.1,"setosa" +5.4,3.7,1.5,0.2,"setosa" +4.8,3.4,1.6,0.2,"setosa" +4.8,3,1.4,0.1,"setosa" +4.3,3,1.1,0.1,"setosa" +5.8,4,1.2,0.2,"setosa" +5.7,4.4,1.5,0.4,"setosa" +5.4,3.9,1.3,0.4,"setosa" +5.1,3.5,1.4,0.3,"setosa" +5.7,3.8,1.7,0.3,"setosa" +5.1,3.8,1.5,0.3,"setosa" +5.4,3.4,1.7,0.2,"setosa" +5.1,3.7,1.5,0.4,"setosa" +4.6,3.6,1,0.2,"setosa" +5.1,3.3,1.7,0.5,"setosa" +4.8,3.4,1.9,0.2,"setosa" +5,3,1.6,0.2,"setosa" +5,3.4,1.6,0.4,"setosa" +5.2,3.5,1.5,0.2,"setosa" +5.2,3.4,1.4,0.2,"setosa" +4.7,3.2,1.6,0.2,"setosa" +4.8,3.1,1.6,0.2,"setosa" +5.4,3.4,1.5,0.4,"setosa" +5.2,4.1,1.5,0.1,"setosa" +5.5,4.2,1.4,0.2,"setosa" +4.9,3.1,1.5,0.2,"setosa" +5,3.2,1.2,0.2,"setosa" +5.5,3.5,1.3,0.2,"setosa" +4.9,3.6,1.4,0.1,"setosa" +4.4,3,1.3,0.2,"setosa" +5.1,3.4,1.5,0.2,"setosa" +5,3.5,1.3,0.3,"setosa" +4.5,2.3,1.3,0.3,"setosa" +4.4,3.2,1.3,0.2,"setosa" +5,3.5,1.6,0.6,"setosa" +5.1,3.8,1.9,0.4,"setosa" +4.8,3,1.4,0.3,"setosa" +5.1,3.8,1.6,0.2,"setosa" +4.6,3.2,1.4,0.2,"setosa" +5.3,3.7,1.5,0.2,"setosa" +5,3.3,1.4,0.2,"setosa" From d7d21cf15886947dcd8f280855694fe9d115fb14 Mon Sep 17 00:00:00 2001 From: selidris <92063773+selidris@users.noreply.github.com> Date: Thu, 4 Nov 2021 20:38:05 -0400 Subject: [PATCH 2/3] Add files via upload --- Exercise7.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Exercise7.R b/Exercise7.R index 9c583a2..6928704 100644 --- a/Exercise7.R +++ b/Exercise7.R @@ -26,7 +26,7 @@ sum(sumspecies$Species=="setosa") #get rows with Sepal.Width > 3.5 sw<-(iris[iris$Sepal.Width>3.5,]) -print(sw) +sw #write the data for the species setosa to a comma-delimited file names ‘setosa.csv’ setosa<-subset(iris, Species=="setosa") From 17ab26c8c074eda8df6df0d9306f4bd5b1c7c613 Mon Sep 17 00:00:00 2001 From: selidris <92063773+selidris@users.noreply.github.com> Date: Thu, 4 Nov 2021 20:40:54 -0400 Subject: [PATCH 3/3] Add files via upload --- Exercise7.R | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Exercise7.R b/Exercise7.R index 6928704..e550534 100644 --- a/Exercise7.R +++ b/Exercise7.R @@ -20,20 +20,24 @@ iris[149:150,4:5] #get the number of observations for each species included in the data set sumspecies<-iris[order(iris$Species, decreasing=TRUE),] + sum(sumspecies$Species=="virginica") sum(sumspecies$Species=="versicolor") sum(sumspecies$Species=="setosa") #get rows with Sepal.Width > 3.5 sw<-(iris[iris$Sepal.Width>3.5,]) + sw #write the data for the species setosa to a comma-delimited file names ‘setosa.csv’ setosa<-subset(iris, Species=="setosa") + write.csv(setosa, file="setosa.csv", row.names=FALSE) #calculate the mean, minimum, and maximum of Petal.Length for observations from virginica v=iris[iris$Species=="virginica",] + mean(v$Petal.Length) max(v$Petal.Length) min(v$Petal.Length) \ No newline at end of file