collapseIntervals {dembase} | R Documentation

## Collapse intervals.

### Description

Merge intervals within a dimension of a `DemographicArray` object. The dimension must have `dimscale` `"Intervals"`.

### Usage

    collapseIntervals(
      object,
      dimension,
      breaks = NULL,
      width = NULL,
      old = NULL,
      weights,
      ...
    )

    ## S4 method for signature 'Counts,ANY,numeric,missing,missing,missing'
    collapseIntervals(
      object,
      dimension,
      breaks = NULL,
      width = NULL,
      old = NULL,
      weights
    )

    ## S4 method for signature 'Counts,ANY,numeric,'NULL','NULL',missing'
    collapseIntervals(
      object,
      dimension,
      breaks = NULL,
      width = NULL,
      old = NULL,
      weights
    )

    ## S4 method for signature 'Counts,ANY,missing,numeric,missing,missing'
    collapseIntervals(
      object,
      dimension,
      breaks = NULL,
      width = NULL,
      old = NULL,
      weights
    )

    ## S4 method for signature 'Counts,ANY,'NULL',numeric,'NULL',missing'
    collapseIntervals(
      object,
      dimension,
      breaks = NULL,
      width = NULL,
      old = NULL,
      weights
    )

    ## S4 method for signature 'Counts,ANY,missing,missing,character,missing'
    collapseIntervals(
      object,
      dimension,
      breaks = NULL,
      width = NULL,
      old = NULL,
      weights
    )

    ## S4 method for signature 'Counts,ANY,'NULL','NULL',character,missing'
    collapseIntervals(
      object,
      dimension,
      breaks = NULL,
      width = NULL,
      old = NULL,
      weights
    )

    ## S4 method for signature 'Counts,ANY,missing,missing,numeric,missing'
    collapseIntervals(
      object,
      dimension,
      breaks = NULL,
      width = NULL,
      old = NULL,
      weights
    )

    ## S4 method for signature 'Counts,ANY,'NULL','NULL',numeric,missing'
    collapseIntervals(
      object,
      dimension,
      breaks = NULL,
      width = NULL,
      old = NULL,
      weights
    )

    ## S4 method for signature 'Counts,ANY,ANY,ANY,ANY,Counts'
    collapseIntervals(
      object,
      dimension,
      breaks = NULL,
      width = NULL,
      old = NULL,
      weights
    )

    ## S4 method for signature 'Values,ANY,ANY,ANY,ANY,ANY'
    collapseIntervals(
      object,
      dimension,
      breaks = NULL,
      width = NULL,
      old = NULL,
      weights
    )

### Arguments

`object` | Object of class `DemographicArray`.
`dimension` | Name or index of the dimension where the intervals are found.
`breaks` | Numeric vector giving the breaks between intervals after the merging has occurred.
`width` | The length of the intervals after the merging has occurred.
`old` | The labels of the intervals to be merged.
`weights` | Object of class `Counts` or the number `1`. Required when `object` has class `Values` and prohibited when it has class `Counts`.
`...` | Not currently used.

### Details

Only one of `breaks`, `width`, and `old` should be supplied.

`breaks` must be a subset of the current breaks between intervals. The first and last breaks can be omitted, as these are always retained by `collapseIntervals`.

`width` is a shortcut version of `breaks` for the common case where all of the collapsed intervals will have the same width (apart from any open intervals). It is equivalent to setting breaks equal to `seq(from = a, to = b, by = width)` where `a` is the lowest (finite) break in `dimension`, and `b` is the highest.

`old` allows intervals to be identified by their labels, as with `collapseCategories`. Unlike with `collapseCategories`, however, no `new` argument is required (since it can be deduced from `old`, and the elements of `old` must be consecutive.

If `weights` equals `1`, all cells are receive equal weights.

### See Also

`collapseCategories`, `collapseIterations`, `collapseOrigDest`, `collapseDimension`, `dimscales`

### Examples

    library(demdata)
    popn <- Counts(VAPopn)
    collapseIntervals(popn, dimension = "age", breaks = c(50, 60, 70, 75))

    ## same results if first and last breaks omitted
    collapseIntervals(popn, dimension = "age", breaks = c(60, 70))

    ## won't work since distance between first and last breaks
    ## not divisible by 10
    ## Not run:
    collapseIntervals(popn, dimension = "age", width = 10)

    ## End(Not run)

    ## works if last age group omitted
    popn.trunc <- subarray(popn, age < 70)
    collapseIntervals(popn.trunc, dimension = "age", width = 10)

    ## selection via labels
    collapseIntervals(popn, dimension = "age", old = c("60-64", "65-69", "70-74"))

    ## weights needed when collapsing objects of class "Values"
    rates <- Values(VADeaths2)
    collapseIntervals(rates, dimension = "age", breaks = 65, weights = popn)
    collapseIntervals(rates, dimension = "age", breaks = 65, weights = 1)

[Package dembase version 0.0.0.119 Index]