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
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.Rproj.user
.Rhistory
.RData
.Ruserdata
13 changes: 13 additions & 0 deletions Biocomp_tutorial9.Rproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Version: 1.0

RestoreWorkspace: Default
SaveWorkspace: Default
AlwaysSaveHistory: Default

EnableCodeIndexing: Yes
UseSpacesForTab: Yes
NumSpacesForTab: 2
Encoding: UTF-8

RnwWeave: Sweave
LaTeX: pdfLaTeX
46 changes: 46 additions & 0 deletions Exercise7.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#Exercise 7

#Problem 1
#Define variable with the file to return lines from
y=read.table(file="wages.csv", header=TRUE,stringsAsFactors = FALSE, sep = ",")
y
#Variable Representing number of lines returned from file
#Where first column contains row number and x is variable number of lines
#that will be returned.
z<-y[c(1:x),]
z

#Problem 2
#Load in Iris data
Irisdata=read.table(file="iris.csv", header = TRUE, stringsAsFactors = FALSE, sep = ",")
Irisdata
#Part a
#Print the last 2 rows
last2R=Irisdata[149:150,]
last2R
#Print the last 2 columns in the last 2 rows
print("Last two rows in the last 2 columns")
last2C=last2R[,4:5]
last2C
#Part b
setosa<-Irisdata[Irisdata$Species=="setosa",]
nrow(setosa)
versicolor<-Irisdata[Irisdata$Species=="versicolor",]
nrow(versicolor)
virginica<-Irisdata[Irisdata$Species=="virginica",]
nrow(virginica)
#Part c
c<-Irisdata[Irisdata[,2]>3.5,]
c
#Part d
setosa<-Irisdata[Irisdata$Species=="setosa",]
write.csv(setosa,"~/Biocomp_tutorial9/setosa.csv", row.names = FALSE)
SetosaDelimited=read.table(file="setosa.csv", header = TRUE, stringsAsFactors = FALSE, sep = ",")
SetosaDelimited
# Part e
virginica<-Irisdata[Irisdata$Species=="virginica",]
e<-virginica[,3]
e
mean(e)
min(e)
max(e)
20 changes: 20 additions & 0 deletions Untitled.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
wages=read.csv(file='wages.csv')
wages[15,]
min(wages[,4])
min(wages$wage)
wages$wage[10]
max(wages$wage)
wages[wages$wage==max(wages$wage),c(1,3)]
#All female gender
wages[wages$gender=='female',c(1,3)]
#Which row is the max in??
which(wages$wage==max(wages$wage))

#Appending vectors (have to switch to numeric and truncate character)
a=c(10,15,32,64)
a[2]*a[4]
b=c(a,'Pat')
b
b[1]*b[3]
b<-as.numeric(b)
b[1]*b[3]
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"