diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5b6a065 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +.Rproj.user +.Rhistory +.RData +.Ruserdata diff --git a/Biocomp_tutorial9.Rproj b/Biocomp_tutorial9.Rproj new file mode 100644 index 0000000..8e3c2eb --- /dev/null +++ b/Biocomp_tutorial9.Rproj @@ -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 diff --git a/Exercise7.R b/Exercise7.R new file mode 100644 index 0000000..2f7b2a7 --- /dev/null +++ b/Exercise7.R @@ -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) \ No newline at end of file diff --git a/Untitled.R b/Untitled.R new file mode 100644 index 0000000..0e3e6f0 --- /dev/null +++ b/Untitled.R @@ -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] 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"