Project 1 - Temperature metric converter

Author
Affiliation

Andrew Moles

Learning Developer, Digital Skills Lab

Published

September 25, 2025

Learning objectives:

  • Create variables
  • Use calculations on variables
  • Print out helpful message about conversion

Outcomes

We will write a program that can convert temperature data. Your code will automate the process of taking data and making it into a presentable format.

Make a Celsius to Fahrenheit temperature converter

We will write a programme that converts Celsius to Fahrenheit, and Fahrenheit to Celsius. It will then write out a helpful message.

We have two temperatures from a given time in London and New York. The London temperature is in Celsius, and the New York temperature is in Fahrenheit. In the outputs the numbers are rounded to zero decimal places. We are aiming for the following outputs:


The temperature in London is 25Β°C, which is 77Β°F

The temperature in New York is 80Β°F, which is 27Β°C


Steps to help you get to the outcome

Part 1 - the setup

Open an R script file and save it.

Part 2 - printing values

Print the value 25.

Part 3 - Celsius to Fahrenheit calculation

Transform the value of 25 Celsius to Fahrenheit with this formula:

\((Celsius \times 9/5) + 32\)

Part 4 - using variables

Store the value of the temperature in Celsius (25) and print it using the stored value.

There are some useful resources online which can help you such as W3schools.

Part 5 - calculations using variables

Use the stored Celsius value to calculate the temperature in Fahrenheit.

Store the outcome of this calculation and print it using the stored value.

Part 6 - more calculations

Store the value of 80 Fahrenheit, then transforming 80 Fahrenheit to Celsius with this formula:

\((Fahrenheit - 32) \times 5/9\)

Store the the outcome of the calculation. Print the outcome using the stored value.

Part 7 - making a text output

Now we can bring it all together to make our final output as seen in SectionΒ 2.1.

Use R to make the two text outputs by concatenating elements from one or more variables into a single string.

This should be automated, so if we change the variable for Celsius or Fahrenheit the code will show the new output.

You can search online here, or use the built in help page in RStudio.

For example, the paste() function will help you here. Try running ?paste to bring up the help page in RStudio.

Part 8 - tidy up

Round the outputs to make sure we are looking at whole numbers only. You will need to assign this result to a variable to use in your output.

Part 9 - try different temperatures

Test out your code by converting different temperatures.

Change your temperature variables to the following and re-run your code:

  • 10 Celsius as Fahrenheit
  • 20 Fahrenheit as Celsius

What should my code look like?

Ideally, your code should have at minimum four variables:

  • The London temperature in Celsius
  • The New York temperature in Fahrenheit
  • The London temperature converted from Celsius to Fahrenheit
  • The New York temperature converted from Fahrenheit to Celsius

You may have more such as variables for the text outputs you made.

Final task - fill out the survey!

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