Learn R Programming

SDMtune (version 0.1.0)

thinData: Thin Data

Description

Remove all but one location per raster cell. The function removes NAs and if more than one location falls within the same raster cell it selects randomly one.

Usage

thinData(coords, env)

Arguments

coords

data.frame or matrix with the coordinates.

env

stack containing the environmental variables, or a single raster layer.

Value

a data frame with the thinned locations.

Details

coords and env must have the same coordinate reference system.

Examples

Run this code
# NOT RUN {
# Acquire environmental variables
files <- list.files(path = file.path(system.file(package = "dismo"), "ex"),
                    pattern = "grd", full.names = TRUE)
predictors <- raster::stack(files)

# Prepare background locations
bg_coords <- dismo::randomPoints(predictors, 9000)

nrow(bg_coords)

# Thin the locations
thinned_bg <- thinData(bg_coords, env = predictors)
nrow(thinned_bg)
# }

Run the code above in your browser using DataLab