cov_n: Sample Covariance for Numeric Vectors

Description Usage Arguments Value Examples

View source: R/RcppExports.R

Description

Written in C++, this function should always run faster than cov for numeric vectors. For integer vectors, cov_i should run even faster.

Usage

1
cov_n(x, y)

Arguments

x, y

Numeric vector.

Value

Numeric value.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
# In general, cov_n is much faster than cov
x <- rnorm(1000)
y <- rnorm(1000)
all.equal(cov(x, y), cov_n(x, y))
benchmark(cov(x, y), cov_n(x, y), replications = 5000)

# For integer vectors, cov_i should be even faster.
x <- rpois(1000, lambda = 5)
y <- rpois(1000, lambda = 5)
all.equal(cov(x, y), cov_i(x, y))
benchmark(cov(x, y), cov_n(x, y), cov_i(x, y), replications = 5000)

dvmisc documentation built on May 2, 2019, 5:51 p.m.

Related to cov_n in dvmisc...