add_dim_nest: Add a dimension representing a higher-level set of categories

Description Usage Arguments Value See Also Examples

Description

Add an extra dimension to an array x. Categories for an existing dimension in x must nest within categories for the new dimension. For instance, if an existing dimension in x is districts, the extra dimension might be the provinces that the disticts belong to. The relationship between the existing lower-level categories and the new upper-level categories is described by data frame nest.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
add_dim_nest(x, nest)

## S4 method for signature 'array'
add_dim_nest(x, nest)

## S4 method for signature 'Counts'
add_dim_nest(x, nest)

## S4 method for signature 'Counts'
add_dim_nest(x, nest)

Arguments

x

An array, including a DemographicArray.

nest

A data.frame providing a mapping between the higher-level and lower-level categories.

Value

An object with the same class as x, but with an extra dimension.

See Also

zero_matrix_nest creates a matrix describing the relationship between the upper-level and lower-level categories.

Examples

1
2
3
4
5
6
7
8
x <- array(1:6,
           dim = c(2, 3),
           dimnames = list(sex = c("Female", "Male"),
                           district = c("A", "B", "C")))
nest <- data.frame(province = c("X", "Y", "X"),
                   district = c("A", "B", "C"))
x
add_dim_nest(x = x, nest = nest)

johnrbryant/demzero documentation built on June 15, 2020, 11:39 p.m.