pchanges: Lagged Proportion Changes

Description Usage Arguments Value Examples

View source: R/RcppExports.R

Description

Calculates proportion changes between subsequent (or lagged) elements of a vector.

Usage

1
pchanges(x, lag = 1L)

Arguments

x

Numeric vector.

lag

Numeric value (e.g. 2 for differences between 1st and 3rd element, 2nd and 4th, ...).

Value

Numeric vector.

Examples

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

# Calculate vector of proportion changes between subsequent values
(y <- pchanges(x))

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

vandomed/stocks documentation built on Sept. 2, 2018, 10:10 a.m.