Learn R Programming

gor (version 2.0)

neigh_index: Previous, current, and next positions of a given index in a cycle.

Description

Previous, current, and next positions of a given index in a cycle.

Usage

neigh_index(i, n)

Value

A three component vector c(previous, current, next)

Arguments

i

Position in a cycle

n

Length of the cycle

Author

Cesar Asensio

Details

Given some position i in a n-length cycle, this function returns the triple c(i-1,i,i+1) taking into account that the next position of i=n is 1 and the previous position of i=1 is n. It is used to perform a 4-exchange in a cycle.

Examples

Run this code
neigh_index(6, 9)  # 5 6 7
neigh_index(9, 9)  # 8 9 1
neigh_index(1, 9)  # 9 1 2

Run the code above in your browser using DataLab