Learn R Programming

weathermetrics (version 1.2.2)

convert_temperature: Convert from one temperature metric to another

Description

This function allows you to convert a vector of temperature values between Fahrenheit, Celsius, and degrees Kelvin.

Usage

convert_temperature(temperature, old_metric, new_metric, round = 2)

Arguments

temperature
A numeric vector of temperatures to be converted.
old_metric
The metric from which you want to convert. Possible options are:
  • fahrenheit, f
  • kelvin, k
  • celsius, c
new_metric
The metric to which you want to convert. The same options are possible as for old_metric.
round
An integer indicating the number of decimal places to round the converted value.

Value

A numeric vector with temperature converted to the metric specified by the argument new_metric.

Examples

Run this code
data(lyon)
lyon$TemperatureF <- convert_temperature(lyon$TemperatureC,
   old_metric = "c", new_metric = "f")
lyon

data(norfolk)
norfolk$TempC <- convert_temperature(norfolk$TemperatureF,
   old_metric = "f", new_metric = "c")
norfolk

data(angeles)
angeles$TemperatureC <- convert_temperature(angeles$TemperatureK,
   old_metric = "kelvin", new_metric = "celsius")
angeles

Run the code above in your browser using DataLab