How to randomly select polygons
I would take the same approach I would for most other things.
1. Count the number of observations
2. Define your sample size
3. Sample `n` from 1:N
4. Use those as an index to subset from
nc <- sf::st_read(system.file("shape/nc.shp", package = "sf"))
n <- 10
idx <- sample(1:nrow(nc), n)
nc[idx, ]
On Mon, Sep 23, 2024 at 2:45?PM Manuel Sp?nola <mspinola10 at gmail.com> wrote:
Dear list members,
How can I select polygons at random from an sf or terra vector (polygon or
multipolygon geometry).
For example for the nc file:
nc = st_read(system.file("shape/nc.shp", package="sf"))
Manuel
--
*Manuel Sp?nola, Ph.D.*
Instituto Internacional en Conservaci?n y Manejo de Vida Silvestre
Universidad Nacional
Apartado 1350-3000
Heredia
COSTA RICA
mspinola at una.cr <mspinola at una.ac.cr>
mspinola10 at gmail.com
Tel?fono: (506) 8706 - 4662
Sitio web institucional: ICOMVIS
<http://www.icomvis.una.ac.cr/index.php/manuel>
Sitio web personal: Sitio personal <https://mspinola-sitioweb.netlify.app>
Blog sobre Ciencia de Datos: Blog de Ciencia de Datos
<https://mspinola-ciencia-de-datos.netlify.app>
[[alternative HTML version deleted]]
_______________________________________________ R-sig-Geo mailing list R-sig-Geo at r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-geo