Learn R Programming

iemisc (version 0.5.0)

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

encoding

UTF-8

Details

CV is expressed as

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

[object Object],[object Object]

References

  1. Masoud Olia, Ph.D., P.E. and Contributing Authors,Barron’s FE (Fundamentals of Engineering Exam), 3rd Edition, Hauppauge, New York: Barron’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
library(iemisc)

# 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