I have a set of existing
sf points and want to randomly sample 1 point from each of a 1km2 grid cell over a landscape.
I can create a grid of 1km2 polygons, but I can't work out in
sf how to then sample points within these polygons.
library("sf") polys <- st_read(system.file("shape/nc.shp", package="sf")) polys <- polys[1:3,] polys <- st_geometry(polys) %>% st_cast("POLYGON") pts <- st_sample(polys, 30) plot(polys) plot(pts, add = TRUE)
Now I want to extract one element of
pts for each polygon in
polys, with the result looking like:
Is there a function to do this within the