pdiffs: Lagged Proportion Differences

Description Usage Arguments Value Examples

View source: R/RcppExports.R

Description

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

Usage

1
pdiffs(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 differences between subsequent values
(y <- pdiffs(x))

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

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