Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions Exercise7.R
Original file line number Diff line number Diff line change
@@ -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)
51 changes: 51 additions & 0 deletions setosa.csv
Original file line number Diff line number Diff line change
@@ -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"