sd2: Sample Standard Deviation

Description Usage Arguments Value References Examples

Description

This is a faster version of base R function sd. For optimal speed, use integer = TRUE if x is an integer vector and integer = FALSE otherwise. Note that for long vectors the function Var in Rfast is typically much faster than sd2. Also, this function uses a one-pass variance calculation that makes it susceptible to precision issues if x values are very large.

Usage

1

Arguments

x

Integer or numeric vector.

integer

Logical value for whether x is an integer vector.

Value

Numeric value.

References

Papadakis, M., Tsagris, M., Dimitriadis, M., Fafalios, S., Tsamardinos, I., Fasiolo, M., Borboudakis, G., Burkardt, J., Zou, C. and Lakiotaki, K. (2018) Rfast: A Collection of Efficient and Extremely Fast R Functions. R package version 1.8.8. https://CRAN.R-project.org/package=Rfast.

Examples

1
2
3
4
5
6
7
8
9
# sd2 vs. sd for integer vector
x <- rpois(1000, lambda = 5)
all.equal(sd(x), sd2(x, integer = TRUE))
benchmark(sd(x), sd2(x, integer = TRUE), replications = 2000)

# sd2 vs. sd for numeric vector
x <- rnorm(1000)
all.equal(sd(x), sd2(x))
benchmark(sd(x), sd2(x), replications = 2000) 

vandomed/crowdopt documentation built on May 26, 2019, 5:35 a.m.