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)
- Download the R code handout here
- 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")
- You can also download the data directly using the following R function:
- 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 theread_csv
function from the tidyverse package
- You can read the data file (.csv) in R using either the
mydata<-read.csv("./dataFolder/mydata.csv")
library(tidyverse)
mydata<-read_csv("./dataFolder/mydata.csv")
- You can use the lecture slides here as reference, but you can also use other sources like cheat sheets and google.
Expected assignment outputs
- As as reference, the following are the outputs expected for each of the tasks listed in the handout.
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)
- Accept the “Manipulating data” assignment here
- Clone your repository in a local directory using Rstudio
- 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
- Go to this link and download the .xlsx file.
- Open the file in a spreadsheet program and save the trait tab into a .csv file (comma delimited)
- 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