This function adds a grid variable to a data frame containing x and y coordinates. The grid variable represents the grid cell in which each coordinate point falls.

add_grid_variable(coords_df, nr, grid_name = "grid", keep_temp = FALSE)

Arguments

coords_df

A data frame containing x and y coordinates.

nr

The number of grid cells required. The square root of this number determines the number of breaks for the x and y axes.

grid_name

The name of the new grid variable to be added to the data frame. Default is "grid".

keep_temp

Logical. If TRUE, temporary variables used in the process (x_bins.temp and y_bins.temp) are retained in the output data frame. Default is FALSE.

Value

A data frame with the added grid variable.

library(SPATA2)

data("example_data")

object <- example_data$object_UKF275T_diet

coords_df <- getCoordsDf(object) %>% add_grid_variable(nr = 50)

print(coords_df)