GHRtools
  • data4health
    • Overview
    • Reference
    • Changelog

    • Vignettes
    • Getting started
    • Access health data
  • clim4health
    • Overview
    • Reference
    • Changelog

    • Vignettes
    • Getting started
    • Glossary
    • s2dv_cube objects
    • Get function
    • Downscaling function
    • Verification function
  • GHRexplore
    • Overview
    • Reference
    • Changelog

    • Vignettes
    • Getting started
  • GHRmodel
    • Overview
    • Reference
    • Changelog

    • Vignettes
    • Getting started
    • Covariate structures
    • DLNMs in GHRmodel
  • GHRpredict
    • Overview
  • About GHR

On this page

  • c4h_convert_units
    • Description
    • Arguments
    • Returns
    • Examples

c4h_convert_units

Description

Convert the units of a variable or variables in an s2dv_cube. If the β€˜to’ argument is NULL, the current units will be displayed instead of performing any conversion.

c4h_convert_units(data, to = NULL, var = NULL, from = NULL)

Arguments

  • data: An s2dv_cube object containing the data to be converted.
  • to: A character string specifying the target units to convert to. If NULL, no conversion will be performed and the current units will be displayed. The default is NULL.
  • var: A character string specifying the variable to convert. If NULL, all variables will be converted. The default is NULL.
  • from: A character string specifying the current units of the variable. If NULL, the current units will be inferred from the data. The default is NULL.

Returns

An s2dv_cube object with the converted units.

Examples

# Forecast data included in the package
fcst_path <- system.file("extdata/forecast/", package = "clim4health")
fcst_path <- paste0(fcst_path, "/")

# Load the forecast data
fcst <- c4h_load(fcst_path,
                 var = "t2m",
                 year = 2025,
                 month = 1,
                 ext = 'nc')

# Display the current units
c4h_convert_units(fcst, var = "t2m")

# Convert from Kelvin to Celsius
fcst_celsius <- c4h_convert_units(fcst,
                                  to = "celsius",
                                  var = "t2m",
                                  from = "K")

Copyright 2026, GHR

 

BSC IDExtremes HARMONIZE Wellcome