R/fish.bins.R

Defines functions fish.bins

Documented in fish.bins

#' Bin for \code{\link{make.catch}}
#' 
#' Creates histogram bins suitable for use with \code{\link{make.catch}}
#' 
#' @param lens vector of fish lengths (e.g. fork length)
#' @param binsize size of histogram bins with which to categorize fish 
#'   by their length
#' 
#' @return a vector of the breakpoints between bins, suitable for
#'   inputing as the breaks argument in \code{\link{hist}}.
#' 
#' @export
fish.bins <-
function(lens, binsize){
	
	#####################################################################
	#
	# fish.bins(): creates histogram bins suitable for use with
	#    make.catch()
	#
	# REQUIRES:  na
	# REQUIRED BY:  make.catch()
	#
	# lens: vector of fish lengths (e.g. fork length)
	# binsize: size of histogram bins with which to categorize fish
	# 	by their length
	# 
	# L,R: left/right boundary of histogram (these ensure that all of
	#    the fish lengths will be within the boundaries and that the
	#    maximum (minimum) sizes will be in the rightmost (leftmost)
	#    bins).  the binning strategy also ensures 'pretty' bins if
	#	a nice 'round' number is chosen for binsizes.
	#
	# output: a vector of the breakpoints between bins, suitable for
	#   inputing as the breaks argument in hist().
	#
	#####################################################################
	
	L <- floor(min(lens,na.rm=TRUE)/binsize)*binsize
	R <- ceiling(max(lens,na.rm=TRUE)/binsize)*binsize
	output <- seq(from=L,to=R,by=binsize)
	return(output)
}

Try the omnr.gillnet package in your browser

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

omnr.gillnet documentation built on May 2, 2019, 6:09 p.m.