#Lowri Jones
#1801539

#1. Load data into dataframe keeping the headers - 
#firstly had to make sure that it was stored in the working directory.

      irisData<-read.csv("iris.csv", header=TRUE)

#2. Make a loop to count the number of instance
# of each species, record the species and number
# in a new data frame.  

      generateSummary<-function (df)
      {
          #creating a vector for all of the species
  
          species<-c("Iris-setosa", "Iris-versicolor",
             "Iris-virginica")
  
          #creating individual vectors for the number of each
        
          countSetosa<-0
          countVersicolor<-0
          countVirginica<-0
          
          #Loop.
          
          for(i in seq(irisData$Species))
          {
            # Increment each counter as appropriate
            if(irisData$Species[i]=="Iris-setosa") countSetosa<-countSetosa+1
            if(irisData$Species[i]=="Iris-versicolor") countVersicolor<-countVersicolor+1
            if(irisData$Species[i]=="Iris-virginica") countVirginica<-countVirginica+1
          }
          
          # Displaying the numbers of each.
          countSetosa
          countVersicolor
          countVirginica
          
          # Putting the count vectors inside another vector for the dataframe
          numberAppearing<-c(countSetosa, countVersicolor, countVirginica)
          
          #binding the two vectors into a dataframe
          irisSummary<-data.frame(species, numberAppearing)
          
          # Displaying the data frame
          irisSummary
  
      }

#3. Calculate the Pearson Correlation between 
# petal length and sepal length (assuming there
# are no missing values in the data set.)

      #creating the dataframe that I am going to be using
      dataAnalyse<-data.frame(irisData$Petal.length, irisData$Sepal.length)

      #calculating the pearson correlation.
      cor(dataAnalyse,method="pearson")

#4. Plot a scatterplot of the petal length and sepel
# length, label both axes and a plot title.
      
      plot(y=irisData$Petal.length, x=irisData$Sepal.length, 
           ylab="Petal Length", xlab="Sepal Length",
           main= "Petal Length vs. Sepal Length")
      
#5. Using a function applied to the irisData data frame,
# add a new column to irisData that shows the petal area for each petal.
    
      areaSetosa<-apply(irisData,calculateArea())
      areaVersicolor<-apply(irisData,calculateArea())
      areaViginica<-apply(irisData,calculateArea())
      
      irisData<-cbind(irisData, areaSetosa, areaVersicolor, areaViginica)
      
      calculateArea<-function(i)
      {
        irisSetosa<- (petalWidth)*(petalLength)*0.8
        irisVersicolor<- (petalwidth)*(petalLength)*0.75
        irisVirginica<- (petalWidth)*(petalLength)*0.65
      }
      
