midpoints: Replace intervals by their midpoints.

Description Usage Arguments Details Value See Also Examples

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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
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)

StatisticsNZ/dembase documentation built on Dec. 25, 2021, 4:49 p.m.