ineigh: Get neighbor indices

Description Usage Arguments Details Value Author(s) Examples

View source: R/gol.R

Description

A fast function to get neighbor indices.

Usage

1
ineigh(i, n, nrow, ncol)

Arguments

i

Source pixel ID number.

n

Number of neighbors to get. For a 3x3 neighborhood, this value is set to 1 (a single neighbor to each of the eight sides of the pixel).

nrow

The number of rows in the raster.

ncol

The number of columns in the raster.

Details

This is a fast function to get the indices of the neighbors to a pixel. It does not require the matrix/raster object, only the number of rows and columns, to find the neighbors. It returns the sorted indices for the pixel, including the focal pixel. If at the edge, it returns NAs so the length is always the number of neighbors asked.

Value

A vector with integer indices.

Author(s)

Pedro Tarroso

Examples

1
2
	# the 3x3 neighbors of pixel 34, on a matrix with 200 rows and columns
	ineigh(34, 1, 200, 200)

ptarroso/gameR documentation built on Nov. 17, 2021, 12:33 a.m.