shm: Harmonic mean

Description Usage Arguments Details Value References See Also Examples

Description

This function computes the sample harmonic mean.

Usage

1
shm(x, na.rm = FALSE)

Arguments

x

numeric vector that contains the sample data points.

na.rm

logical vector that determines whether the missing values should be removed or not.

Details

Harmonic mean is expressed as

\bar{x}_h = \frac{1}{≤ft(\frac{1}{n}\right)≤ft[≤ft(\frac{1}{x_1}\right) + ≤ft(\frac{1}{x_2}\right) + \cdots + ≤ft(\frac{1}{x_n}\right)\right]}

\bar{x}_h

the sample harmonic mean

x

the values in a sample

n

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."

Value

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).

References

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.

See Also

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.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
library("iemisc")
library("data.table")

# Example 1.12 from Kottegoda (page 13)
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)

iemisc documentation built on Aug. 2, 2020, 9:07 a.m.