library(sp)
library(sf)
library(meteo)
# prepare data
# load observation - data.frame of mean temperatures
demo(meuse, echo=FALSE)
meuse <- meuse[complete.cases(meuse@data),]
locations = st_as_sf(meuse, coords = c("x", "y"), crs = 28992, agr = "constant")
locations = # terra::rast(meuse.grid)
observations = st_as_sf(meuse, coords = c("x", "y"), crs = 28992, agr = "constant")
# find 5 nearest observations and distances to them (remove duplicates)
nearest_obs <- near.obs.soil(locations = locations, # from
locations.x.y.md = c("x","y","dist"),
observations = observations, # to
observations.x.y.md= c("x","y","dist"),
obs.col = "zinc",
n.obs = 5) # number of nearest observations
str(nearest_obs)
summary(nearest_obs)
Run the code above in your browser using DataLab