R/convert_p.R

Defines functions convert_p

Documented in convert_p

## -----------------------------------------------------------------------------
## Conversion Between Different Barometric Units
## -----------------------------------------------------------------------------

convert_p <- function(x, unit = c("Pa", "bar", "at", "atm", "torr")) {
  if (!is.numeric(x)) stop("x must be numeric")
  ## factors taken from Wikipedia
  unit    <- match.arg(unit)
  factors <- c(Pa = 1, bar = 1e-5, at = 1.0197e-5, atm = 9.8692e-6, torr = 7.5006e-3)
  units   <- names(factors)
  p       <- match(unit, units)
  as.data.frame(x %o% factors / factors[p])
}

Try the marelac package in your browser

Any scripts or data that you put into this service are public.

marelac documentation built on Sept. 25, 2023, 5:06 p.m.