iemisc (version 0.9.8)

cv: Coefficient of variation (CV)

Description

This function computes the sample coefficient of variation (CV).

Usage

cv(x, na.rm = FALSE)

Arguments

x

numeric vector, matrix, data.frame, or data.table that contains the sample data points.

na.rm

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

Value

coefficient of variation (CV), as a percent (%), as an R object: a numeric vector or a named numeric vector if using a named object (matrix, data.frame, or data.table). 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 cv(x, na.rm = TRUE).

Details

CV is expressed as

$$\frac{s}{\bar{x}} \cdot 100$$

s

the sample standard deviation

\(\bar{x}\)

the sample arithmetic mean

References

  1. Masoud Olia, Ph.D., P.E. and Contributing Authors, Barron<U+2019>s FE (Fundamentals of Engineering Exam), 3rd Edition, Hauppauge, New York: Barron<U+2019>s Educational Series, Inc., 2015, page 84.

  2. Irwin R. Miller, John E. Freund, and Richard Johnson, Probability and Statistics for Engineers, Fourth Edition, Englewood Cliffs, New Jersey: Prentice-Hall, Inc., 1990, page 25, 38.

See Also

sgm for geometric mean, shm for harmonic mean, rms for root-mean-square (RMS), relerror for relative error, approxerror for approximate error, and ranges for sample range.

Examples

Run this code
# NOT RUN {
library("iemisc")
library("data.table")

# Example 2.60 from Miller (page 38)
x <- c(14, 12, 21, 28, 30, 63, 29, 63, 55, 19, 20) # suspended solids in
     # parts per million (ppm)
cv(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))), "Samples"))
cv(mat1)


# using a data.frame of the numeric vector x
df1 <- data.frame(x)
cv(df1)


# using a data.table of the numeric vector x
df2 <- data.table(x)
cv(df2)


# }

Run the code above in your browser using DataLab