A function to generate time bins for a given study interval. This function is flexible in that either stage-level or higher stratigraphic-level (e.g. period) time bins can be called. In addition, near equal-length time bins can be generated by grouping stages together. For example, for 10 Myr as a target bin size, the function will generate groups of bins that have a mean bin length close to 10 Myr. However, users may also want to consider grouping stages based on other reasoning e.g. availability of outcrop (see Dean et al. 2020).

## Usage

```
time_bins(
interval = "Phanerozoic",
rank = "stage",
size = NULL,
assign = NULL,
scale = "GTS2020",
plot = FALSE
)
```

## Arguments

- interval
`character or numeric`

. Interval name available in`GTS2020`

or`GTS2012`

. If a single interval name is provided, this interval is returned. If two interval names are provided, these intervals and those existing between are returned. If a single numeric age is provided, the interval that covers this age is returned. If two numeric ages are provided, the intervals occurring in the range of these ages are returned. Defaults to "Phanerozoic".- rank
`character`

. Which stratigraphic rank is desired? Choose from: "stage", "epoch", "period", "era", and "eon". If`scale`

is a dataframe, this argument is ignored.- size
`numeric`

. If equal-length time bins are desired, specify the length in millions of years (Myr) of the time bins desired.- assign
`numeric`

. A numeric vector of age estimates to use to assign to requested bins. If assign is specified, a numeric vector is returned of the midpoint age of the specified bins. Note this is the simplified approach of assignment in`palaeoverse`

included for data with 'known' point-age estimates. For a wider range of binning methods, see`palaeoverse::bin_time()`

.- scale
`character`

or`data.frame`

. Specify the desired geological timescale to be used "GTS2020" (default), "GTS2012" or a user-input`data.frame`

. If a`data.frame`

is provided, it must contain at least the following named columns: "interval_name", "max_ma", and "min_ma". Column names "name", "max_age", and "min_age" are also accepted, but these are assumed to be equivalent to the aforementioned. As such, age data should be provided in Ma.- plot
`logical`

. Should a plot of time bins be generated?

## Value

A `dataframe`

of time bins for the specified intervals or a
list with a `dataframe`

of time bins and a named `numeric`

vector (bin number) of binned age estimates (midpoint of specified bins) if assign is specified.

## Details

This function uses either the Geological Time Scale 2020,
Geological Time Scale 2012, or a user-input `data.frame`

(see `scale`

argument) to generate time bins. Interval data hosted by Macrostrat are
also compatiable and accessible via the deeptime R pacakge
(`get_scale_data`

).
Additional information on included Geological Time Scales and source can be
accessed via:

Available intervals names are accessible via the `interval_name`

column in `GTS2012`

and `GTS2020`

. Data of the Geological Timescale 2020
and 2012 were compiled by Lewis A. Jones (2022-07-02).

## References

Dean, C.D., Chiarenza, A.A. and Maidment, S.C., 2020. Formation binning: a new method for increased temporal resolution in regional studies, applied to the Late Cretaceous dinosaur fossil record of North America. Palaeontology, 63(6), 881-901. doi:10.1111/pala.12492 .

## Examples

```
#Using numeric age
ex1 <- time_bins(interval = 10, plot = TRUE)
#Using numeric age range
ex2 <- time_bins(interval = c(50, 100), plot = TRUE)
#Using a single interval name
ex3 <- time_bins(interval = c("Maastrichtian"), plot = TRUE)
#Using a range of intervals and near-equal duration bins
ex4 <- time_bins(interval = c("Fortunian", "Meghalayan"),
size = 10, plot = TRUE)
#> Target equal length time bins was set to 10.02 Myr.
#> Generated time bins have a mean length of 10.82 Myr and a standard deviation of 2.41 Myr.
#Assign bins based on given age estimates
ex5 <- time_bins(interval = c("Fortunian", "Meghalayan"),
assign = c(232, 167, 33))
#Use user-input data.frame to generate near-equal length bins
scale <- data.frame(interval_name = 1:5,
min_ma = c(0, 18, 32, 38, 45),
max_ma = c(18, 32, 38, 45, 53))
ex6 <- time_bins(scale = scale, size = 20, plot = TRUE)
#> Target equal length time bins was set to 17.67 Myr.
#> Generated time bins have a mean length of 17.67 Myr and a standard deviation of 2.52 Myr.
#Use North American land mammal ages from deeptime/Macrostrat
scale <- deeptime::get_scale_data(name = "North American land mammal ages")
ex7 <- time_bins(scale = scale, size = 10)
#> Target equal length time bins was set to 9.43 Myr.
#> Generated time bins have a mean length of 9.43 Myr and a standard deviation of 1.19 Myr.
```