Skip to contents

fn_porcentaje: Percentaje

Description

Calculates the percentage of each category (rows) per column (month), and also includes the total number of data per column (N).

For the analysis performed in Salas-Singh et al. (2022), immatures fish may or may not be included in the analysis. If the “immatures” object is assigned zero, they are excluded from the analysis, any non-zero value includes them.

It returns a table with the percentage of each category and N.

The function requires defining:

  • df: A data frame array, including the number of data by factor level (rows) and month (column).
  • meses: A vector of characters representing the initials of the months of the year.
  • immatures: An integer value defined outside this function.
  • Phases_legend: A vector with the name or number of the stages of maturity, as specified in the object Phases, outside of this function. Legend for phases: 1 roman numeral, 2 names.

Seealso: FDist from the package stats (version 3.6.2)

fn_porcentaje

The function is included in the Repbio package Reproductive biology analysis.

#library(Repbio)

The function is detailed below.

fn_porcentaje <- function(df, meses, immatures, Phases_legend) {
  # Total data number per column
  n_mes <- round(apply(X= df, MARGIN=2, FUN= sum),0)
  n_mes[n_mes == 0] <- "-"
  # Percentage calculation
  for (ii in 1:length(meses)) {
    if(sum(df[,ii]) == 0){
      df[ii] <-"-"
    }else{
      df[ii] <- round(100*df[,ii]/sum(df[,ii]),0)
    }  #end if
  } #end for

  # Add total data number per column
  countsp <- rbind (df,n_mes)
  names(countsp) <-meses
      if (immatures == 0){
          rownames(countsp) <- c(Phases_legend[-c(1)],"N")
      } else{
          rownames(countsp) <- c(Phases_legend,"N")
      } # end if
  countsp
} # end Function

Examples

Falta detallar el ejemplo. This is an example … . The immatures are excluded from the analysis, giving them a value of zero.

    # df <- tmp
    # meses <- c("J","F","M","A","M","J","J","A","S","O","N","D")
    # immatures <- 0
    # Phases_legend <- c("II", "III", "IV", "V", "VI")
    # ejemplo <- fn_porcentaje(df, meses, immatures, Phases_legend)

References

Salas‐Singh, C., Morales‐Bojórquez, E., & Aguirre‐Villaseñor, H. (2022). Reproductive biology of the bullseye puffer Sphoeroides annulatus: Gonadosomatic index and its suitability for estimating length at maturity. Journal of Fish Biology, 101(5), 1119-1133.https://doi.org/10.1111/jfb.15174