R/nbfam.R

Defines functions nbfam

Documented in nbfam

#' This function is allows you to calculate the number of species per family in a floristic data table
#'
#' @param x data matrix of floristic inventory, the name of each colum is as follow : 'genera', 'epit.spec', 'specie', 'family', 'life.form', 'chorology'.
#' @keywords family
#' @author Evans Ehouman
#' @return to a data.frame of number of species in each family.
#' @import dplyr
#' @examples
#' @export

nbfam= function(x) {
  if (!requireNamespace("dplyr", quietly = TRUE)) {
    stop("R package 'dplyr' needed for this function to work. Please install it.\n",
         "install.packages('dplyr')", call. = FALSE)
  }
  #Calcualte Number of species by genera
  outputfam1 <- as.data.frame(table(x[,4]))
  Var1 <- Freq <- NULL # Setting the variables to NULL first
  #Pass the result to a dataframe and change the name of the colums
  outputfam<- outputfam1 %>%
    dplyr::rename(
      Families= Var1,
      Number.of.species =  Freq
    )

  return(outputfam)
}
EhoumanEvans/TaxaRich documentation built on Aug. 26, 2020, 5:27 a.m.