ratios: Ratios of Subsequent Elements in a Vector

Description Usage Arguments Value Examples

View source: R/RcppExports.R

Description

Calculates vector of ratios of a vector, i.e. ratio of x[2] to x[1], ratio of x[3] to x[2], and so forth.

Usage

1
ratios(x)

Arguments

x

Numeric vector.

Value

Numeric vector.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
# Generate 10 values from N(0, 1)
x <- rnorm(10)

# Calculate vector of ratios
(y <- ratios(x))

# Slower base R computation
len <- length(x)
y2 <- x[2: len] / x[1: (len - 1)]
all.equal(y, y2)

vandomed/stocks documentation built on July 22, 2020, 3:25 a.m.