cv | R Documentation |
This function computes the sample coefficient of variation (CV).
cv(x, na.rm = FALSE)
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. |
CV is expressed as
\frac{s}{\bar{x}} \cdot 100
the sample standard deviation
\bar{x}
the sample arithmetic mean
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)
.
Irucka Embry
r - How to not run an example using roxygen2? - Stack Overflow answered and edited by samkart on Jul 9 2017. (Also see the additional comments in response to the answer.) See https://stackoverflow.com/questions/12038160/how-to-not-run-an-example-using-roxygen2.
devtools - Issues in R package after CRAN asked to replace dontrun by donttest - Stack Overflow answered by Hong Ooi on Sep 1 2020. (Also see the additional comments in response to the answer.) See https://stackoverflow.com/questions/63693563/issues-in-r-package-after-cran-asked-to-replace-dontrun-by-donttest.
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.
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.
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.
# Example 2.60 from Miller (page 38)
library(iemisc)
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
df <- data.frame(x)
cv(df)
# using a data.table of the numeric vector x
library("data.table")
dt <- data.table(x)
cv(dt)
# modified Example 2.60 from Miller (page 38)
xx <- c(14, 12, 21, 28, 30, 63, 29, 63, 55, 19, 20, NA)
# suspended solids in parts per million (ppm)
cv(xx) # na.rm = FALSE is the default
cv(xx, na.rm = TRUE)
# See Source 1 and Source 2
# Example 3
# Please see the error messages
library(iemisc)
try(cv(0))
try(cv(1))
try(cv(1003.23))
# Example 4 - from the archived cvcqv README
xu <- c(0.2, 0.5, 1.1, 1.4, 1.8, 2.3, 2.5, 2.7, 3.5, 4.4, 4.6, 5.4,
5.4, 5.7, 5.8, 5.9, 6.0, 6.6, 7.1, 7.9)
results2 <- cv(xu)
results2
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.