7  Week 2 Lab Exercise

For this exercise, we’re going to use the skills we’ve gathered so far to look at daily temperature variability using three years worth of weather data from Rarotonga. Follow these steps to complete this assignment:

Download the RarotongaWeather2020.csv file from Canvas and save it to the Data folder. Create a new R script called tempAnalysis and save it to the Code folder.In this script, write code and comments that will do the following:

  1. Read the raroWeather2020.csv file into R as a tibble

  2. Combine the 2020, 2021, and 2022 tibbles by row into a single dataset

  3. Create a new column called tempDiff that gives the difference between the maximum and minimum temperature for the entire dataset (note: there may be a fair number of NA values here)

  4. Export the modified data to a .csv file and save it to the Data folder

  5. Make a histogram of the temperature differences for the period 2020-2022. Make sure to use the main and xlab arguments to give the histogram an appropriate main title and x-axis label. Save the histogram image to the Output folder.

  6. Be sure to save all the components of this project.

For the submission, include the histogram, your script, and the combined .csv file. Grading criteria can be found on Canvas.

Stretch activity (optional)

If you haven’t had enough R for one night, here’s a little extra just for fun:

Right now, the DATE field is stored as character strings, but if we wanted to use this for visualization, we’d need objects that treat these as sequential dates.

When you loaded tidyverse, you also loaded a package called lubridate, which helps you convert between date formats. Search the help for the ymd function. This and others like it transform dates that are in particular formats (e.g., year-month-day). Figure out which one you would need to use for the dates we have, then use it to convert the character dates into date objects. You’ll know you got it right if you can plot average temperature by date.