Description Usage Arguments Value Note Examples
This function is used to subsample a RasterLayer
or matrix
by
dividing the dataset into a grid of horizcells
x vertcells
,
and by then drawing a sample of size nsamp
from within each grid
cell.
1 2 | gridsample(x, horizcells = 10, vertcells = 10, nsamp = 10,
rowmajor = FALSE, replace = FALSE)
|
x |
a matrix or RasterLayer to draw sample from |
horizcells |
how many cells to break the raster in horizontally (over the columns) |
vertcells |
how many cells to break the raster in vertically (over the rows) |
nsamp |
how many samples to draw from each grid cell |
rowmajor |
whether to return indices in row-major format (default is
column-major). Row-major format is useful in conjunction with |
replace |
whether to sample with replacement (within each grid cell) |
vector of sample indices
TODO: Recode in C++ for speed.
1 2 3 4 5 6 | # Make a 100x100 matrix
x <- matrix(1:10000, nrow=100)
# Subsample the matrix by breaking it up into a 10 x 10 grid, and take 10
# random samples from each grid cell without replacement (these are the
# default parameters).
y <- gridsample(x)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.