Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

move_n_point

Move a vector n elements forward or backward.


Description

Move a vector n elements forward or backward.

Usage

move_n_point(x, n = 1, na_value = NA)

Arguments

x

A vector.

n

Number indicating how many steps the vector should shift forward (N > 0) or backward (n < 0).

na_value

The value to replace the empty cells with (e.g., the first or last points). Defaults to NA.

Value

A vector with the same length of x, all moved n steps.

Author(s)

Jacolien van Rij

See Also

Examples

(x <- -10:30)
prev <- move_n_point(x)
change <- x - prev
post5 <- move_n_point(x, n=-5)

emptyPlot(length(x), range(x))
lines(x)
lines(prev, col='red')
lines(post5, col='blue')

plotfunctions

Various Functions to Facilitate Visualization of Data and Analysis

v1.4
GPL (>= 2)
Authors
Jacolien van Rij [aut, cre]
Initial release
2020-04-30

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.