gridsample: Draw a random sample from a grid laid out on a RasterLayer or...

Description Usage Arguments Value Note Examples

View source: R/gridsample.R

Description

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.

Usage

1
2
gridsample(x, horizcells = 10, vertcells = 10, nsamp = 10,
  rowmajor = FALSE, replace = FALSE)

Arguments

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 Raster* objects.

replace

whether to sample with replacement (within each grid cell)

Value

vector of sample indices

Note

TODO: Recode in C++ for speed.

Examples

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)

azvoleff/teamlucc documentation built on June 4, 2017, 12:08 a.m.