Project 2 - Weather application

Author
Affiliation

Andrew Moles

Learning Developer, Digital Skills Lab

Published

September 25, 2025

Learning objectives:

  • Create vectors
  • Use calculations on vectors
  • Concatenate data to make a daily weather report

Outcomes

We will write a program that tells us various metrics on what the weather is doing. Your code will automate the process of taking data and making it into a presentable format.

Make a daily weather report:

You should end up with a output that has three lines:

  1. Line one should have the date
  2. Line two should have lows and highs in Celsius and Fahrenheit (in brackets)
  3. Line three should have the average temperature in Celsius and Fahrenheit (in brackets)
[1] "Temperature on: 30/06/2025"
[1] "Low: 17.7°C (63.86°F) | High: 32.4°C (90.32°F)"
[1] "Daily average: 26.03°C (78.85°F)"

Optional additional output

Tidy the output to be one string separated by lines.

Temperature on: 30/06/2025
Low: 17.7°C (63.86°F) | High: 32.4°C (90.32°F)
Daily average: 26.03°C (78.85°F)

The data

Using the data below we will be making a weather reporting tool for a daily report.

Hourly temperatures:

20.8, 19.6, 18.7, 17.8, 17.7, 19.1, 21.4, 22.8, 24.1, 26.5, 27.8, 29.4, 30.7, 31.8, 32.4, 32.0, 31.8, 31.5, 31.2, 29.9, 28.3, 27.1, 26.2

Date and times:

"30/06/2025 01:00:00", "30/06/2025 02:00:00", "30/06/2025 03:00:00", "30/06/2025 04:00:00", "30/06/2025 05:00:00", "30/06/2025 06:00:00","30/06/2025 07:00:00", "30/06/2025 08:00:00", "30/06/2025 09:00:00", "30/06/2025 10:00:00", "30/06/2025 11:00:00", "30/06/2025 12:00:00","30/06/2025 13:00:00", "30/06/2025 14:00:00", "30/06/2025 15:00:00", "30/06/2025 16:00:00", "30/06/2025 17:00:00", "30/06/2025 18:00:00","30/06/2025 19:00:00", "30/06/2025 20:00:00", "30/06/2025 21:00:00", "30/06/2025 22:00:00", "30/06/2025 23:00:00"

Steps to help you get to the outcome

Part 1 - the setup

Open an R script file and save it.

Part 2 - using vectors

A vector in R is a one-dimensional array of data that is the same data type. Using the data shown above, store the hourly temperatures and date and times data into R as vectors.

Part 3 - indexing vectors

Index the date and time vector to extract just the first element. Store the result as a variable.

Part 4 - string manipulation

Extract part of the string, known as substrings, from the variable you just made. Store the result as a variable. you should get the result below.

30/06/2025

We want to do this programmatically, so no copy and pasting from the data, also known as “hardcoding”. This will help us to automate our code if we want to use different data.

Part 5 - calculate temperatures

Calculate the lowest (minimum), highest (maximum), and average (mean) temperatures, storing the results as variables. If needed, round the results so it is more presentable.

Part 6 - convert temperatures

Convert the lowest, highest, and average temperatures from Celsius to Fahrenheit and store the results.

Part 7 - making the text output

Print out the string messages that show you the daily weather report with both Celsius and Fahrenheit, as shown in Section 2.1.

Part 8 - test your code with new data

A good way to test out your code is to try it on different data.

Below we have the temperature data for a few days after the data we have been using. Using the steps you did previously, write a weather report using this new data.

Hourly temperatures:

16.5, 15.5, 14.3, 13.7, 12.4, 12, 12.6, 14.1, 16, 18.2, 19.7, 21.1, 21.8, 22.6, 23.4, 24.3, 23.3, 23.6, 23.1, 23.4, 23.4, 21.6, 20.7, 19.5

Date and times:

"03/07/2025 00:00:00", "03/07/2025 01:00:00", "03/07/2025 02:00:00", "03/07/2025 03:00:00", "03/07/2025 04:00:00", "03/07/2025 05:00:00", "03/07/2025 06:00:00", "03/07/2025 07:00:00", "03/07/2025 08:00:00", "03/07/2025 09:00:00", "03/07/2025 10:00:00", "03/07/2025 11:00:00", "03/07/2025 12:00:00", "03/07/2025 13:00:00", "03/07/2025 14:00:00", "03/07/2025 15:00:00", "03/07/2025 16:00:00", "03/07/2025 17:00:00", "03/07/2025 18:00:00", "03/07/2025 19:00:00", "03/07/2025 20:00:00", "03/07/2025 21:00:00", "03/07/2025 22:00:00", "03/07/2025 23:00:00" ### Final task - fill out the survey!

We are always looking to improve and iterate our workshops. Follow the link to give your feedback.