Skip to content
Open
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
41 changes: 41 additions & 0 deletions Ex08.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Exercise 08
setwd("/Users/bethoceguera/Documents/PhD Year 1/First Semester/Introduction to Biocomputing/Exercise08")

# 1. Write R code that replicates the functionality of the head function we used in bash
data <- read.csv("iris.csv")
data[1:6,]

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The assignment asked you to set a variable to the number of lines to be extracted. This is missing here

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-0.25


##DONE

# 2. Load the data contained in the provided 'iris.csv' file and write R code to do the following things
# Print the last two rows in the last 2 columns to the R terminal
data <- read.csv("iris.csv")
str(data) #to check how many rows and columns (150 rows, 5 columns)
data[149:150,4:5]

# Get the number of observations for each species included in the data set
setosa <- nrow(data[data$Species=="setosa",]) #Number of observations for setosa
versicolor <- nrow(data[data$Species=="versicolor",]) #Number of observations for versicolor
virginica <- nrow(data[data$Species=="virginica",]) # Number of observations for virginica
# Table summarizing results
SummaryTable <- data.frame(Species=c("Setosa","Versicolor","Virginica"),numberObservations=c(setosa,versicolor,virginica))

# Get rows with Sepal.Width > 3.5
SepalWidth <- data[data$Sepal.Width>3.5,]

# Write the data for the species setosa to a comma-delimited file named "setosa.csv"
write.table((data[data$Species=="setosa",]), "setosa.csv",sep = ",")

# Write the mean, minimum, and maximum of Petal.Length for observations from virgincia
virginicaRows <- data[data$Species=="virginica",]
mean <- mean(virginicaRows$Petal.Length) #mean
min <- min(virginicaRows$Petal.Length) #minimum
max <- max(virginicaRows$Petal.Length) #max
# Table summarizing results
SummTable <- data.frame(Peramter=c("Mean","Minimum","Maximum"),Value=c(mean,min,max))

##DONE