get_neighbors | R Documentation |
Function to obtain the neighbors of each tree from a file containing the identities of the trees and, optionally, a variable that identifies the plots.
get_neighbors(df, plot_ID, coords, suffixes, max_dist = 10000)
df |
the data frame containing the trees for which we want to identify the neighbors, and their associated information |
plot_ID |
**optional**. Variable that identifies the plots, or experimental units, within which the neighbors will be searched. If this variable exists, a tree "a" can only be a neighbor of another tree "b", if it is fulfilled that plot(a) == plot(b). |
coords |
**optional** Character vector containing the names of the columns in 'df'containing the x and y coordinates of the trees. By default 'coords = c("x", "y")', i.e. it assumes taht the columns are called "x" and "y" |
suffixes |
**optional** character vector containing the suffixes that will be added to the variables in 'df'to dientify target trees and neighbours. By default it takes the value 'suffixes = c("_target", "_neighbor")', but can take any other value defined by user. |
max_dist |
numeric Maximum distance to search for neighbours of target trees. It takes value 10000 by default. |
This function identifies the neighbors of each potential "target" tree and creates a data frame that contains a row for each neighbor of each tree in the original data frame. Variables characterizing target and neighbor trees are identified with the suffixes "_target" and "_neighbour", respectively. It also computes the distance between each target - neighbor pair, in the same units as provided by the "x" and "y" coordinates.
data(tree_data) neighbors <- get_neighbors(tree_data, plot) # If not plots are to be considered all_neighbors <- get_neighbors(tree_data) # specify suffix for target and neighbors, and maximum distance neighbors2 <- get_neighbors(tree_data, plot, suffixes = c("cible", "voisin"), max_dist = 10)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.