comps_bins: Bin a vector of data into groups

View source: R/comps_bins.R

comps_binsR Documentation

Bin a vector of data into groups

Description

Bin a vector of data into distinct groups, this is often helpful for grouping ages or lengths into bin categories if every year or centimeter is not its own bin.

Usage

comps_bins(
  vector,
  breaks,
  includeplusgroup = TRUE,
  returnclass = c("character", "numeric")
)

Arguments

vector

A vector of information that will be manipulated.

breaks

A vector of cut points to be passed to cut.

includeplusgroup

A logical defining if you want all values larger than the largest break to be included in the last bin. For example, if the largest value in breaks is 15 and you have age-20 fish, then you should use includeplusgroup = TRUE if you want to have data on this 20 year old fish. The default is to include them.

returnclass

The class() of the returned object. This is helpful for those times when numeric values are characters or the opposite. Sometimes you wish to force the results to be a certain class and this argument can help define the class of the returned object. Note that not all classes are always available. The default will be the first entry in the function call.

Author(s)

Kelli F. Johnson

Examples

comps_bins(1:8, breaks = c(-Inf, 3:5))
comps_bins(1:8, breaks = c(3:5), includeplusgroup = FALSE)
testthat::expect_equal(
comps_bins(1:8, breaks = c(-Inf, 3:5, Inf)),
comps_bins(1:8, breaks = c(-Inf, 3:5), includeplusgroup = TRUE)
)


nwfsc-assess/PacFIN.Utilities documentation built on March 19, 2024, 11:54 p.m.