#' Subsample a dataset by species
#'
#' Sample a dataset as if we only recorded some species.
#'
#' @param dataset A data frame containing abundance or incidence data
#' @param count The number of species to retain
#' @return The subsampled dataset as a tibble
#'
#' @export
#'
#' @examples
#' library(iNEXT)
#' data(bird)
#' sample_by_species(bird, count = 2)
#'
#' data(ciliates)
#' eto.incidence <- ciliates$EtoshaPan
#' sample_by_species(eto.incidence, 5)
#'
sample_by_species <- function(dataset, count)
{
rows <- nrow(dataset)
if (count > rows)
{
warning("Trying to pick more species than are present")
count = rows
}
return(tibble::as_data_frame(dataset[sample(rows, count), ]))
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.