From 8be2af452e340ce5bf5ee9623543f394a6c5859e Mon Sep 17 00:00:00 2001 From: Katherine Urasky Date: Thu, 4 Nov 2021 17:11:51 -0400 Subject: [PATCH] Turn in my Tutorial 9 homework --- Tutorial9_answers.R | 48 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 Tutorial9_answers.R diff --git a/Tutorial9_answers.R b/Tutorial9_answers.R new file mode 100644 index 0000000..0687851 --- /dev/null +++ b/Tutorial9_answers.R @@ -0,0 +1,48 @@ +#### Below is my answer to question 1 + +wages <- read.table(file="wages.csv", header=TRUE, sep=",", stringsAsFactors=FALSE) +wages +number_of_lines <- 10 +wages[1:number_of_lines,] + +#### Below is my answer to question 2 +iris <- read.table(file="iris.csv", header=TRUE, sep=",", stringsAsFactors = FALSE) +iris + +# Below is my answer to 2.a +iris[149:150,4:5] + +# Below is my answer to 2.b +setosa <- iris[iris$Species=="setosa",] +setosa +number_setosa <- nrow(setosa) +number_setosa +#number_setosa is a variable which holds the number of setosa observations + +versicolor <- iris[iris$Species=="versicolor",] +versicolor +number_versicolor <- nrow(versicolor) +number_versicolor +#number_versicolor is a variable which holds the number of versicolor observations + +virginica <- iris[iris$Species=="virginica",] +virginica +number_virginica <- nrow(virginica) +number_virginica +#number_virginica is a variable which holds the number of virginica observations + +# Below is my answer to 2.c +sepal_width <- iris[iris$Sepal.Width>3.5,] +sepal_width +#sepal_width is a variable which holds the number of observations with sepal width > 3.5 + +# Below is my answer to 2.d +write.table(setosa, file="setosa.csv", sep=",", dec=".", row.names=FALSE, col.names=TRUE) + +# Below is my answer to 2.e +mean_petal_length <- mean(virginica$Petal.Length) +mean_petal_length +min_petal_length <- min(virginica$Petal.Length) +min_petal_length +max_petal_length <- max(virginica$Petal.Length) +max_petal_length \ No newline at end of file