shm | R Documentation |
This function computes the sample harmonic mean.
shm(x, na.rm = FALSE)
x |
numeric vector that contains the sample data points. |
na.rm |
logical vector that determines whether the missing values should be removed or not. |
Harmonic mean is expressed as
\bar{x}_h = \frac{1}{\left(\frac{1}{n}\right)\left[\left(\frac{1}{x_1}\right) + \left(\frac{1}{x_2}\right) + \cdots + \left(\frac{1}{x_n}\right)\right]}
\bar{x}_h
the sample harmonic mean
the values in a sample
the number of values
"The harmonic mean is the reciprocal of the mean of the reciprocals. It is applied in situations where the reciprocal of a variable is averaged."
sample harmonic mean as a numeric vector. The default choice is that
any NA values will be kept (na.rm = FALSE
). This can be changed by
specifying na.rm = TRUE
, such as shm(x, na.rm = TRUE)
.
Irucka Embry
Nathabandu T. Kottegoda and Renzo Rosso, Statistics, Probability, and Reliability for Civil and Environmental Engineers, New York City, New York: The McGraw-Hill Companies, Inc., 1997, page 13.
mean
for arithmetic mean
sgm
for geometric mean, cv
for coefficient of
variation (CV), relerror
for relative error, approxerror
for
approximate error, rms
for root-mean-square (RMS), and ranges
for sample range.
# Example 1.12 from Kottegoda (page 13)
install.load::load_package("iemisc", "data.table")
x <- c(0.20, 0.24, 0.16) # stream velocities in m/s
shm(x)
# using a matrix of the numeric vector x
mat1 <- matrix(data = x, nrow = length(x), ncol = 1, byrow = FALSE,
dimnames = list(c(rep("", length(x))), "Velocities"))
shm(mat1)
# using a data.frame of the numeric vector x
df1 <- data.frame(x)
shm(df1)
# using a data.table of the numeric vector x
df2 <- data.table(x)
shm(df2)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.