Learn R Programming

itsadug (version 0.8)

move_n_point: Utility function.

Description

Utility function.

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.

See Also

Other Data utility functions: findAbsMin; find_n_neighbors; group_sort; print_summary; summary_data

Examples

Run this code
data(simdat)
(test <- simdat[1:20,])
test$Y.prev <- move_n_point(test$Y)
test$change <- test$Y - test$Y.prev
test$Y.post5 <- move_n_point(test$Y, n=-5)

emptyPlot(nrow(test), range(test$Y))
lines(test$Y)
lines(test$Y.prev, col='red')
lines(test$Y.post5, col='blue')

Run the code above in your browser using DataLab