Learning Objectives

Following this assignment students should be able to:

  • Read files in R
  • Understand data manipulation functions in R
  • Summarise dataframes
  • Subset dataframes
  • Write csv files
  • Create basic plots

Exercises

Assignment 1 (Homework)

  1. Download the R code handout here
  2. Download the data from here
    • You can also download the data directly using the following R function:
      download.file("https://ndownloader.figshare.com/files/2292169", "./dataFolder/mydata.csv")
      
  3. Import the data file you just downloaded and complete the task listed on the R code handout
    • You can read the data file (.csv) in R using either the read.csv function or the read_csv function from the tidyverse package
mydata<-read.csv("./dataFolder/mydata.csv")

library(tidyverse)
mydata<-read_csv("./dataFolder/mydata.csv")

Expected assignment outputs

Task Expected output
2 output, .txt
3 output, .txt
4.1 output, .txt
4.2 output, .txt
4.3 output, .txt
4.4 output, .txt
4.5 output, .txt
4.6 output, .txt
4.7 output, csv

Assignment 2 (in class)

  1. Accept the “Manipulating data” assignment here
  2. Clone your repository in a local directory using Rstudio
  3. For this assignment, we are going to use the Trait plant data from:
    • Razafindratsima OH, Brown KA, Carvalho F, Johnson SE, Wright PC, Dunham AE (2017) Data from: Edge effects on components of diversity and above-ground biomass in a tropical rainforest. Dryad Digital Repository. https://doi.org/10.5061/dryad.jn743
  4. Go to this link and download the .xlsx file.
  5. Open the file in a spreadsheet program and save the trait tab into a .csv file (comma delimited)
  6. In the “code.R” file from the assignment repository, write the necessary R code to:
    • Read the csv file
    • Show the number of unique families found in the data frame
    • Show the number of species in each family
    • Calculate the average fruit width in cm per dispersal mode
    • Create a csv file with all the species that are dispersed by lemurs and have a fruit length > 8 mm
    • Plot the average fruit length per seed size category using (A) all the data, and (B) the lemur subset data

Notes: Do not forget to commit and push your main changes