Learn R Programming

dggridR (version 3.1.0)

dgmaxcell: Get largest cell id for a dggs

Description

Cells are labeled 1-N. This function returns N. This is useful if you want to choose cells from the dggs randomly.

Usage

dgmaxcell(dggs, res = NA)

Value

The maximum cell id.

Arguments

dggs

A dggs object from dgconstruct()

res

If NA, use the resolution specified by the dggs. Otherwise, override the resolution.

Examples

Run this code
#Choose a set of cells randomly distributed over the Earth
library(dggridR)
dggs    <- dgconstruct(spacing=1000, metric=FALSE, resround='down')
N       <- 100                                 #Number of cells
maxcell <- dgmaxcell(dggs)                     #Get maximum cell id
cells   <- sample(1:maxcell, N, replace=FALSE) #Choose random cells
grid    <- dgcellstogrid(dggs,cells) #Get grid

Run the code above in your browser using DataLab