midpoints {dembase} | R Documentation

## Replace intervals by their midpoints.

### Description

Change `"Intervals"` `dimscales` to `"Points"`, replacing each interval with its midpoint. This can be useful for plotting or calculating mean values, among other things. `midpoints` is typically called by other functions, but it may sometimes be useful to call it directly.

### Usage

    midpoints(object, dimension)

    ## S4 method for signature 'Component,ANY'
    midpoints(object, dimension)

    ## S4 method for signature 'Component,missing'
    midpoints(object)

    ## S4 method for signature 'DemographicArray,ANY'
    midpoints(object, dimension)

    ## S4 method for signature 'DemographicArray,missing'
    midpoints(object)

    ## S4 method for signature 'MetaData,integer'
    midpoints(object, dimension)

    ## S4 method for signature 'Population,ANY'
    midpoints(object, dimension)

    ## S4 method for signature 'Population,missing'
    midpoints(object)

### Arguments

`object` | Object of class `DemographicArray`.
`dimension` | Names or indices of dimensions to be converted. If omitted, all dimensions with dimtype `"Intervals"` are converted.

### Details

An object can only have a dimension with `dimtype` `"triangle"` if the object also has age and time dimensions with dimscale `"Intervals"`. When `midpoints` is called on an object with a triangles dimension, the dimtype for that dimension is coerced to `"state"` and the dimscale is coerced to `"Categories"`.

### Value

Object of class `DemographicArray`.

### See Also

`dimscales`, `dplot`

### Examples

    library(demdata)
    rates <- Values(VADeaths2)
    midpoints(rates)

    a <- array(1:4,
               dim = c(2, 2),
               dimnames = list(age = c("0-39", "40+"),
                               period = c("2001-2010", "2011-2020")))
    x <- Counts(a)
    midpoints(x)
    midpoints(x, dimension = c("age", "period"))
    midpoints(x, dimension = "period")
    midpoints(x, dimension = 2)

[Package dembase version 0.0.0.119 Index]