freq: Frequency Functions

View source: R/freq.R

freqR Documentation

Frequency Functions

Description

Functions to generate size-frequency distributions.

Usage

freq(x, ...)

## Default S3 method:
freq(x, n, index, by, fill = TRUE, step, range, ...)

## S3 method for class 'scsbio'
freq(x, category, by, step = 1, variable = "carapace.width", ...)

## S3 method for class 'scslen'
freq(x, variable = "length", by, units = "cm", ...)

## S3 method for class 'nsslen'
freq(
  x,
  variable = "length",
  by = c("date", "vessel.code", "cruise.number", "set.number"),
  units = "cm",
  ...
)

Arguments

x

Vector of numeric values.

n

Vector of numeric frequency values for each x.

index

Numeric or logical indices specifying which elements of x to be analyzed as a subset.

by

Grouping variable.

fill

Logical value specifying whether to interpolate missing frequency bins.

step

Numeric value specifying the width of the frequency bins.

range

Two-element numeric vector specifying the range of values to be included in the resulting frequency table. Use NA or +/- Inf to specify lower or upper open bounds.

category

Character string specifying biological categories. See category for details.

variable

Character string specifying the variable used to generate the frequency table.

Methods (by class)

  • freq(default): Default freq method.

  • freq(scsbio): scsbio freq method.

  • freq(scslen): scslen freq method.

  • freq(nsslen): nsslen freq method.

Examples

# Simple example:
x <- data.frame(values = c(11, 11, 12, 13, 15),
                n      = c(2,1,3,1,1),
                group  = c(1,1,1,2,2),
                sub    = c(1,2,2,3,3))
                
freq(x$values, x$n)  # Frequency table.
freq(x$values, x$n, by = x["group"])  # Frequency table by group.
freq(x$values, x$n, by = x[c("group", "sub")])  # Frequency table by group and subgroup.
  
# Load snow crab biological data:       
x <- read.scsbio(2020)                        

# Default frequency function examples:
freq(x$carapace.width, step = 1) # Size-frequencies using millimeter bins.
freq(x$carapace.width, step = 0.5) # Size-frequencies using half-millimeter bins.
freq(x$carapace.width, by = x["sex"], step = 0.5) # Size-frequencies by sex.
freq(x$carapace.width, by = x[c("sex", "shell.condition")], step = 0.5) # Size-frequencies by sex and shell condition.
freq(x$carapace.width, index = is.category(x, c("MM", "FM")), step = 1) # Size-frequencies for mature male and mature females.
freq(x$carapace.width, index = is.category(x, category()), step = 1)    # All default categories.

# 'scsbio' frequency function examples:
freq(x) # Size-frequencies.
freq(x, by = "sex") # Size-frequencies by sex.
freq(x, by = c("sex", "shell.condition")) # Size-frequencies by sex and shell condition.
freq(x, category = c("MM", "FM")) # Size-frequencies for mature male and mature females.
freq(x, by = c("date" "tow.id"), category = c("MM", "FM")) # Size-frequencies for mature male and mature females.


TobieSurette/gulf.data documentation built on Jan. 19, 2025, 7:50 p.m.