R/to_incidence.R

#' Convert abundance data to incidence data
#'
#' Take an abundance dataset and remove abundance information, leaving
#' only presence (1) and incidence (0) data.
#'
#' @param dataset A data frame containing abundance or incidence data
#' @return The subsampled dataset as a tibble
#'
#' @export
#'
#' @examples
#' library(iNEXT)
#' data(bird)
#' to_incidence(bird)
#'
to_incidence <- function(dataset)
{
  incidence <- lapply(as.list(dataset), to01)
  incidence <- as.data.frame(incidence)
  rownames(incidence) <- rownames(dataset)

  return(tibble::as_data_frame(incidence))
}

to01 <- function(col)
{
  present <- col > 0
  incidence <- present * 1
  return(incidence)
}
boydorr/sampling documentation built on May 23, 2019, 1:45 p.m.