diff --git a/Exercise7.R b/Exercise7.R new file mode 100644 index 0000000..e550534 --- /dev/null +++ b/Exercise7.R @@ -0,0 +1,43 @@ + +#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,]) + +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"