Skip to contents

This function thins a dataset so that only one observation per cell per time slice is retained. We use a raster with layers as time slices to define the data cube on which thinning is enforced (see details below on how time should be formatted).


  coords = NULL,
  time_col = "time",
  lubridate_fun = c,
  drop_na = TRUE,
  agg_fact = NULL



An sf::sf data frame, or a data frame with coordinate variables. These can be defined in coords, unless they have standard names (see details below).


A terra::SpatRaster object that defined the grid with layers corresponding to the time slices (times should be set as either POSIXlt or "years", see terra::time() for details), or a terra::SpatRasterDataset where the first dataset will be used (again, times for that dataset should be set as either POSIXlt or "years") terra::time()


a vector of length two giving the names of the "x" and "y" coordinates, as found in data. If left to NULL, the function will try to guess the columns based on standard names c("x", "y"), c("X","Y"), c("longitude", "latitude"), or c("lon", "lat")


The name of the column with time; if time is not a lubridate object, use lubridate_fun to provide a function that can be used to convert appropriately


function to convert the time column into a lubridate object


boolean on whether locations that are NA in the raster should be dropped.


positive integer. Aggregation factor expressed as number of cells in each direction (horizontally and vertically). Or two integers (horizontal and vertical aggregation factor) or three integers (when also aggregating over layers). Defaults to NULL, which implies no aggregation (i.e. thinning is done on the grid of raster)


An object of class sf::sf or data.frame, the same as "data".


Further spatial thinning can be achieved by aggregating cells in the raster before thinning, as achieved by setting agg_fact > 1 (aggregation works in a manner equivalent to terra::aggregate()).