comps_bins.Rd
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.
comps_bins(
vector,
breaks,
includeplusgroup = TRUE,
returnclass = c("character", "numeric")
)
A vector of information that will be manipulated.
A vector of cut points to be passed to cut.
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.
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.
comps_bins(1:8, breaks = c(-Inf, 3:5))
#> [1] "-Inf" "-Inf" "3" "4" "5" "5" "5" "5"
comps_bins(1:8, breaks = c(3:5), includeplusgroup = FALSE)
#> [1] NA NA "3" "4" NA NA NA NA
testthat::expect_equal(
comps_bins(1:8, breaks = c(-Inf, 3:5, Inf)),
comps_bins(1:8, breaks = c(-Inf, 3:5), includeplusgroup = TRUE)
)