Learn R Programming

itsadug (version 2.0)

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.

See Also

Other Utility functions: convertNonAlphanumeric, diff_terms, findAbsMin, find_difference, find_n_neighbors, getDec, getRange, group_sort, list2str, missing_est, print_summary, se, summary_data, timeBins

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