A simple function that subsamples a data frame or numeric vector in order to "thin" large datasets.
subsample(x, n = NULL, length.out = NULL, random_start = FALSE, plot = TRUE)
data frame or vector. The data to subsample.
numeric. Subsample every n
elements or rows.
numeric. Subsample to a specific length or number of rows.
logical. Defaults to FALSE. If TRUE, randomises the start
position from which to start the subsample (applies to n
input only).
logical. Defaults to TRUE. Plots the data. If there are multiple columns in the data frame, only the first two are plotted. Vectors are plotted against a position index.
Returns a subsampled data frame or vector object depending on input.
Two subsampling methods are provided. The n
input selects every n'th
element or row, or alternatively the length.out
input uniformly subsamples
the data to the desired length.
For additional help, documentation, vignettes, and more visit the respR
website at https://januarharianto.github.io/respR/
# Subsample by every 200th row:
subsample(squid.rd, n = 200)
# Subsample to 100 rows:
subsample(sardine.rd, length.out = 100)
#> subsample: plotting first column of data only.
# Subsample with random starting position:
subsample(sardine.rd, n = 20, random_start = TRUE)
#> subsample: plotting first column of data only.
# Subsample a vector
subsample(sardine.rd[[2]], n = 20)