[R-sig-Geo] How to randomly select polygons

Manuel Spínola m@p|no|@10 @end|ng |rom gm@||@com
Tue Sep 24 00:07:57 CEST 2024


Thank you very much Josiah,

That works for me.

Manuel

El lun, 23 sept 2024 a las 15:54, Josiah Parry (<josiah.parry using gmail.com>)
escribió:

> 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 using 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 using una.cr <mspinola using una.ac.cr>
>> mspinola10 using 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 using r-project.org
>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>>
>

-- 
*Manuel Spínola, Ph.D.*
Instituto Internacional en Conservación y Manejo de Vida Silvestre
Universidad Nacional
Apartado 1350-3000
Heredia
COSTA RICA
mspinola using una.cr <mspinola using una.ac.cr>
mspinola10 using 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]]



More information about the R-sig-Geo mailing list