ratios: Ratios of Subsequent Elements in a Numeric Vector

Description Usage Arguments Value Note Author(s) References See Also Examples

View source: R/RcppExports.R

Description

Calculates vector of ratios of a numeric 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.

Note

This function uses C++ code to achieve a 1.5-2 times speed increase compared to the base R code: len <- length(prices); prices[2: len] / prices[1: (len - 1)].

Author(s)

Dane R. Van Domelen

References

Acknowledgment: This material is based upon work supported by the National Science Foundation Graduate Research Fellowship under Grant No. DGE-0940903.

See Also

diffs, pdiffs, pchanges

Examples

1
2
3
4
5
6
7
8
9
# Randomly generate 10 values from a standard normal distribution
x <- rnorm(10)

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

# View results
x
y

stocks documentation built on May 31, 2017, 3:18 a.m.

Search within the stocks package
Search all R packages, documentation and source code