Learn R Programming

sim2Dpredictr (version 0.1.1)

neighbors_by_dist: Determine and store neighbors by Euclidean Distance Constraints

Description

Determine and store neighbors by Euclidean Distance Constraints

Usage

neighbors_by_dist(x, y, coords, im.res, r, print.ring = FALSE)

Value

A tibble whose first column contains x indices, second column contains y indices, and third column denotes the current ring about a location.

Arguments

x, y

are the row and column coordinates, respectively.

coords

A dataframe containing indices and coordinates for the image.

im.res

A vector containing the number of rows and columns, respectively.

r

A scalar value determining the radius within which other locations are neighbors to the current location (x, y).

print.ring

When print.ring = TRUE, each iteration is shown, with corresponding information regarding the number of neighbors present in each ring. This argument primarily exists to allow the user to test whether the neighborhood structure specified is as desired.

Examples

Run this code
## Necessary pre-specified arguments required for the function to work.

## image resoluation + number of spatial predictors
im.res <- c(5, 5)
J <- prod(im.res)

## create predictor indices w/ coordinates
row.id <-rep(1, im.res[2])
for (i in 2:im.res[1]) {
 row.id <- c(row.id, rep(i, im.res[2]))
}
coords <- data.frame(index = 1:J,
                     row.id = row.id,
                     col.id = rep(c(1:im.res[2]), im.res[1]) )

neighbors_by_dist(x = 2, y = 2, im.res = im.res, coords = coords, r = 2)

Run the code above in your browser using DataLab