Title: | MA Birk's Functions |
---|---|
Description: | Collection of tools to make R more convenient. Includes tools to summarize data using statistics not available with base R and manipulate objects for analyses. |
Authors: | Matthew A. Birk |
Maintainer: | Matthew A. Birk <[email protected]> |
License: | GPL-3 |
Version: | 2.1.2 |
Built: | 2025-02-28 05:32:01 UTC |
Source: | https://github.com/cran/birk |
Collection of tools to make R more convenient. Includes tools to summarize data using statistics not available with base R and manipulate objects for analyses.
Matthew A. Birk, [email protected]
DEPRECATED. Converts between dimensions of measurement given a transition dimension (the dimension that "bridges" x
and y
, e.g. liters per second, lbs per acre). Note that 2 of the 3 measurements (x
, y
, or trans
) must be defined to calculate the 3rd. See conv_unit_options
for all options.
conv_dim(x, x_unit, trans, trans_unit, y, y_unit)
conv_dim(x, x_unit, trans, trans_unit, y, y_unit)
x |
a numeric vector giving the measurement value in the first dimension. |
x_unit |
the unit in which |
trans |
a numeric vector giving the measurement value in the transition dimension. |
trans_unit |
the unit in which |
y |
a numeric vector giving the measurement value in the second dimension. |
y_unit |
the unit in which |
This function supports all dimensions in conv_unit_options
except for coordinates. The conversion values have been defined based primarily from international weight and measurement authorities (e.g. General Conference on Weights and Measures, International Committee for Weights and Measures, etc.). While much effort was made to make conversions as accurate as possible, you should check the accuracy of conversions to ensure that conversions are precise enough for your applications.
Years are defined as 365.25 days and months are defined as 1/12 a year.
cal is a thermochemical calorie (4.184 J) and Cal is 1000 cal (kcal or 4184 J).
All gallon-based units are US gallons.
All non-metric units are based on the avoirdupois system.
hp is mechanical horsepower, or 745.69 W.
mach is calculated at sea level at 15 °C.
Matthew A. Birk, [email protected]
# How many minutes does it take to travel 100 meters at 3 feet per second? conv_dim(x = 100, x_unit = "m", trans = 3, trans_unit = "ft_per_sec", y_unit = "min") # How many degrees does the temperature increase with an increase in 4 kPa given 0.8 Celcius # increase per psi? conv_dim(x_unit = "C", trans = 0.8, trans_unit = "C_per_psi", y = 4, y_unit = "kPa") # Find the densities given volume and mass measurements. conv_dim(x = c(60, 80), x_unit = "ft3", trans_unit = "kg_per_l", y = c(6e6, 4e6), y_unit = "g")
# How many minutes does it take to travel 100 meters at 3 feet per second? conv_dim(x = 100, x_unit = "m", trans = 3, trans_unit = "ft_per_sec", y_unit = "min") # How many degrees does the temperature increase with an increase in 4 kPa given 0.8 Celcius # increase per psi? conv_dim(x_unit = "C", trans = 0.8, trans_unit = "C_per_psi", y = 4, y_unit = "kPa") # Find the densities given volume and mass measurements. conv_dim(x = c(60, 80), x_unit = "ft3", trans_unit = "kg_per_l", y = c(6e6, 4e6), y_unit = "g")
DEPRECATED. Converts common units of measurement for a variety of dimensions. See conv_unit_options
for all options.
conv_unit(x, from, to)
conv_unit(x, from, to)
x |
a numeric vector giving the measurement value in its original units. |
from |
the unit in which the measurement was made. |
to |
the unit to which the measurement is to be converted. |
mm_per_sec2, cm_per_sec2, m_per_sec2, km_per_sec2, grav, inch_per_sec2, ft_per_sec2, mi_per_sec2, kph_per_sec, mph_per_sec
degree, radian, grad, arcmin, arcsec, turn
nm2, um2, mm2, cm2, m2, hectare, km2, inch2, ft2, yd2, acre, mi2, naut_mi2
dec_deg, deg_dec_min, deg_min_sec (see note)
nmol, umol, mmol, mol
nsec, usec, msec, sec, min, hr, day, wk, mon, yr, dec, cen, mil, Ma
J, kJ, erg, cal, Cal, Wsec, kWh, MWh, BTU
ml_per_sec, ml_per_min, ml_per_hr, l_per_sec, l_per_min, l_per_hr, m3_per_sec, m3_per_min, m3_per_hr, gal_per_sec, gal_per_min, gal_per_hr, ft3_per_sec, ft3_per_min, ft3_per_hr, Sv
angstrom, nm, um, mm, cm, dm, m, km, inch, ft, yd, fathom, mi, naut_mi, au, light_yr, parsec, point
ug, mg, g, kg, Pg, carat, metric_ton, oz, lbs, short_ton, long_ton, stone
uW, mW, W, kW, MW, GW, erg_per_sec, cal_per_sec, cal_per_hr, Cal_per_sec, Cal_per_hr, BTU_per_sec, BTU_per_hr, hp
uatm, atm, Pa, hPa, kPa, torr, mmHg, inHg, mbar, bar, dbar, psi
mm_per_sec, cm_per_sec, m_per_sec, km_per_sec, inch_per_sec, ft_per_sec, kph, mph, km_per_day, mi_per_day, knot, mach, light
C, F, K, R
ul, ml, dl, l, cm3, dm3, m3, km3, us_tsp, us_tbsp, us_oz, us_cup, us_pint, us_quart, us_gal, inch3, ft3, mi3, imp_tsp, imp_tbsp, imp_oz, imp_cup, imp_pint, imp_quart, imp_gal
The conversion values have been defined based primarily from international weight and measurement authorities (e.g. General Conference on Weights and Measures, International Committee for Weights and Measures, etc.). While much effort was made to make conversions as accurate as possible, you should check the accuracy of conversions to ensure that conversions are precise enough for your applications.
Years are defined as 365.25 days and months are defined as 1/12 a year.
Values must be entered as a string with one space between subunits (e.g. 70° 33’ 11” = "70 33 11").
cal is a thermochemical calorie (4.184 J) and Cal is 1000 cal (kcal or 4184 J).
All gallon-based units are US gallons.
All non-metric units are based on the avoirdupois system.
hp is mechanical horsepower, or 745.69 W.
mach is calculated at sea level at 15 °C.
Matthew A. Birk, [email protected]
conv_unit(2.54, "cm", "inch") # Result = 1 inch conv_unit(seq(1, 10), "kg", "short_ton") # A vector of measurement values can be converted # Convert 1, 10, and 100 meters to all other length units sapply(conv_unit_options$length, function(x) conv_unit(c(1, 10, 100), "m", x)) conv_unit("33 1 1", "deg_min_sec", "dec_deg") conv_unit(c("101 44.32","3 19.453"), "deg_dec_min", "deg_min_sec")
conv_unit(2.54, "cm", "inch") # Result = 1 inch conv_unit(seq(1, 10), "kg", "short_ton") # A vector of measurement values can be converted # Convert 1, 10, and 100 meters to all other length units sapply(conv_unit_options$length, function(x) conv_unit(c(1, 10, 100), "m", x)) conv_unit("33 1 1", "deg_min_sec", "dec_deg") conv_unit(c("101 44.32","3 19.453"), "deg_dec_min", "deg_min_sec")
DEPRECATED. Shows what units of measurement can be converted with the function conv_unit
.
conv_unit_options
conv_unit_options
A list with all units available for conversion using conv_unit
.
Years are defined as 365.25 days and months are defined as 1/12 a year.
Values must be entered as a string with one space between subunits (e.g. 70° 33’ 11” = "70 33 11").
cal is a thermochemical calorie (4.184 J) and Cal is 1000 cal (kcal or 4184 J).
All non-metric units are based on the avoirdupois system.
hp is mechanical horsepower, or 745.69 W.
mach is calculated at sea level at 15 °C.
Matthew A. Birk, [email protected]
The conversion values have been defined based primarily from international weight and measurement authorities (e.g. General Conference on Weights and Measures, International Committee for Weights and Measures, etc.). While much effort was made to make conversions as accurate as possible, you should check the accuracy of conversions to ensure that conversions are precise enough for your applications.
conv_unit_options conv_unit_options$pressure
conv_unit_options conv_unit_options$pressure
Computes the geometric mean of a vector, x
. It is a wrapper for exp(mean(log(x)))
.
geom_mean(x, add0.001 = FALSE, ignore_neg = FALSE, ...)
geom_mean(x, add0.001 = FALSE, ignore_neg = FALSE, ...)
x |
a numeric vector or an R object which is coercible to one by as.vector(x, "numeric”). |
add0.001 |
logical. Should a small constant (0.001) be added to avoid issues with zeroes? |
ignore_neg |
logical. Should negative values be ignored to avoid NaNs? |
... |
further arguments passed to |
Matthew A. Birk, [email protected]
geom_mean(1:10) geom_mean(0:10) geom_mean(0:10, add0.001 = TRUE) geom_mean(-10:10, add0.001 = TRUE, ignore_neg = TRUE)
geom_mean(1:10) geom_mean(0:10) geom_mean(0:10, add0.001 = TRUE) geom_mean(-10:10, add0.001 = TRUE, ignore_neg = TRUE)
Generates a sequence of numbers spanning the range of x
.
range_seq(x, extend = 0, ...)
range_seq(x, extend = 0, ...)
x |
a numeric vector. |
extend |
number specifying the fraction by which the range should be extended. |
... |
further arguments to be passed to |
Matthew A. Birk, [email protected]
range_seq(rnorm(10, sd = 20)) range_seq(c(3, 9), extend = 0.1) range_seq(c(3, 9), length.out = 20)
range_seq(rnorm(10, sd = 20)) range_seq(c(3, 9), extend = 0.1) range_seq(c(3, 9), length.out = 20)
Computes the standard error of the values in x
. If na.rm
is TRUE then missing values are removed before computation proceeds.
se(x, na.rm = FALSE)
se(x, na.rm = FALSE)
x |
a numeric vector or an R object which is coercible to one by as.vector(x, "numeric”). |
na.rm |
logical. Should missing values be removed? |
Matthew A. Birk, [email protected]
se(1:10)
se(1:10)
Pools summary statistics when given mean and (optionally) a measurement of variability (choose one among var
, sd
, and se
).
summ_stat(mean, n, var, sd, se)
summ_stat(mean, n, var, sd, se)
mean |
numeric. A vector of mean values to be pooled. |
n |
numeric. A vector of n values to be pooled. |
var |
numeric. A vector of variance values to be pooled. |
sd |
numeric. A vector of standard deviation values to be pooled. |
se |
numeric. A vector of standard error of the mean vlaues to be pooled. |
Matthew A. Birk, [email protected]
summ_stat(mean = c(0.68, 0.67), n = c(4, 5), sd = c(0.11, 0.15)) summ_stat(mean = 0.68, n = 3, se = 5) summ_stat(mean = rnorm(1e4), n = rep(1, 1e4)) # Find pooled mean when variability is unknown.
summ_stat(mean = c(0.68, 0.67), n = c(4, 5), sd = c(0.11, 0.15)) summ_stat(mean = 0.68, n = 3, se = 5) summ_stat(mean = rnorm(1e4), n = rep(1, 1e4)) # Find pooled mean when variability is unknown.
Returns index of the closest value to x
.
which.closest(vec, x)
which.closest(vec, x)
vec |
a numeric vector. |
x |
numeric. The value for which the closest match should be returned. |
Matthew A. Birk, [email protected]
which.closest(10:1, 3.3)
which.closest(10:1, 3.3)