R/removesp.R

Defines functions .removeSp

# Function to remove species with values of zero (i.e. species not present in the grid) in PresenceAbscence object
# Bruno Vilela

.removeSp <- function(x) {  
  
  rem <- which(colSums(x[, -(1:2), drop = FALSE]) == 0) + 2
  
  if (length(rem) > 0) {
    x <- x[, -rem, drop = FALSE]
  }
  
  if (ncol(x) == 2) {
    stop("No species left after removing species without occurrences")
  }
  
  return(x)
}

Try the letsR package in your browser

Any scripts or data that you put into this service are public.

letsR documentation built on Oct. 27, 2020, 1:07 a.m.