alignPair: Align categories dimensions that come in pairs.

Description Usage Arguments Details Value See Also Examples

Description

Given an object of class DemographicArray, make dimensions with dimtype "origin" and "destination" or "parent" and "child" consistent. This is done by permuting and inserting rows.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
alignPair(
  object,
  base = NULL,
  omitted = ifelse(methods::is(object, "Counts"), 0L, NA)
)

## S4 method for signature 'DemographicArray'
alignPair(
  object,
  base = NULL,
  omitted = ifelse(methods::is(object, "Counts"), 0L, NA)
)

Arguments

object

Object of class DemographicArray.

base

Character vector giving the "base names" for the dimension pairs. If base is omitted, the base names from all dimensions with dimtype "origin", "destination", "parent", or "child" are used.

omitted

Value to be used for omitted origin-destination or parent-child combinations. Defaults to 0 when object has class Counts and NA otherwise.

Details

The "base name" of a dimension with dimtype "origin", "destination", "parent", or "child" is the name minus the "_orig", "_dest", "_parent", or "_child" suffix. For instance, the base name of "region_orig" and "region_dest" is "region".

Value

An object with the same class as object.

See Also

Function pairAligned tests whether a pair of dimensions use the same categories in the same order.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
x <- Counts(array(1:4,
                 dim = c(2, 2),
                 dimnames = list(region_orig = c("a", "b"),
                 region_dest = c("c", "b"))))
x
alignPair(x, base = "region")
alignPair(x)
alignPair(x, omitted = NA)

y <- Values(array(1:8,
                  dim = c(2, 2, 1, 2),
                  dimnames = list(region_orig = c("a", "b"),
                                  region_dest = c("b", "a"),
                                  ethnicity_parent = "q",
                                  ethnicity_child = c("q", "r"))))
y
alignPair(y, base = "region")
alignPair(y, base = "ethnicity")
alignPair(y)

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