From d208ac18c1c490a6e8beeac3a76943f85d5e72dd Mon Sep 17 00:00:00 2001 From: Casey Novak Date: Thu, 4 Nov 2021 10:15:39 -0400 Subject: [PATCH 1/3] Still need to change end of code, everything else done --- Tutorial9_Answers.R | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 Tutorial9_Answers.R diff --git a/Tutorial9_Answers.R b/Tutorial9_Answers.R new file mode 100644 index 0000000..22254bc --- /dev/null +++ b/Tutorial9_Answers.R @@ -0,0 +1,36 @@ +# Tutorial 9, Exercise 7 + +# Problem 1 + +#Set working directory +setwd("~/Desktop/Fall-2021/Biocomputing/Tutorial9/Biocomp_tutorial9") +list.files() +#Define a variable with the file to return lines from +exampleFile <- read.table("iris.csv",header=TRUE,sep=",") +#Define variable representing the number of lines to be returned from the top of the file +numLines = 8 +#Select certain number of lines from the top of the file (use square bracket indexing) +results <- exampleFile[1:numLines, ] +#Print file content to terminal +results + +# Problem 2 + +# Load data from 'iris.csv' +irisFile <- read.table("iris.csv",header=TRUE,sep=",") +# Print the last two rows in the last two columns to the R terminal +irisFile[149:150,4:5] +# Get the number of observations for each species in the data set +sum(irisFile$Species=='setosa') +sum(irisFile$Species=='versicolor') +sum(irisFile$Species=='virginica') +# Get rows with Sepal.Width > 3.5 +irisFile[irisFile$Sepal.Width>3.5,] +# Write the data for the species setosa to a comma-delimited file named 'setosa.csv' +setosaData<-irisFile[irisFile$Species=='setosa',] +write.csv(setosaData, file = 'setosa.csv',row.names=FALSE) +# Calculate the mean, minimum, and maximum of Petal.Length for observations from virginica +mean(irisFile$Petal.Length[irisFile$Species=='virginica']) +min(irisFile$Petal.Length) +max(irisFile$Petal.Length) #How to select rows that are specific to virginica + From fdefb6008e39ec8ace34a7a3dbeb2769b1aea0d0 Mon Sep 17 00:00:00 2001 From: Casey Novak Date: Thu, 4 Nov 2021 10:46:53 -0400 Subject: [PATCH 2/3] Final answers for exercise #7 --- Tutorial9_Answers.R | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Tutorial9_Answers.R b/Tutorial9_Answers.R index 22254bc..1fcbc78 100644 --- a/Tutorial9_Answers.R +++ b/Tutorial9_Answers.R @@ -4,7 +4,6 @@ #Set working directory setwd("~/Desktop/Fall-2021/Biocomputing/Tutorial9/Biocomp_tutorial9") -list.files() #Define a variable with the file to return lines from exampleFile <- read.table("iris.csv",header=TRUE,sep=",") #Define variable representing the number of lines to be returned from the top of the file @@ -28,9 +27,9 @@ sum(irisFile$Species=='virginica') irisFile[irisFile$Sepal.Width>3.5,] # Write the data for the species setosa to a comma-delimited file named 'setosa.csv' setosaData<-irisFile[irisFile$Species=='setosa',] -write.csv(setosaData, file = 'setosa.csv',row.names=FALSE) +write.csv(setosaData,file = 'setosa.csv',row.names=FALSE) # Calculate the mean, minimum, and maximum of Petal.Length for observations from virginica mean(irisFile$Petal.Length[irisFile$Species=='virginica']) -min(irisFile$Petal.Length) -max(irisFile$Petal.Length) #How to select rows that are specific to virginica +min(irisFile$Petal.Length[irisFile$Species=='virginica']) +max(irisFile$Petal.Length[irisFile$Species=='virginica']) From d180bcefa9148bb361e68ed5154b4215cadfbe74 Mon Sep 17 00:00:00 2001 From: Casey Novak Date: Thu, 4 Nov 2021 10:49:09 -0400 Subject: [PATCH 3/3] Changed one comment --- Tutorial9_Answers.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tutorial9_Answers.R b/Tutorial9_Answers.R index 1fcbc78..5684685 100644 --- a/Tutorial9_Answers.R +++ b/Tutorial9_Answers.R @@ -6,7 +6,7 @@ setwd("~/Desktop/Fall-2021/Biocomputing/Tutorial9/Biocomp_tutorial9") #Define a variable with the file to return lines from exampleFile <- read.table("iris.csv",header=TRUE,sep=",") -#Define variable representing the number of lines to be returned from the top of the file +#Define variable representing the number of lines to be returned from the top of the file (can be any number) numLines = 8 #Select certain number of lines from the top of the file (use square bracket indexing) results <- exampleFile[1:numLines, ]