zero_matrix_nest: Create a structural zero matrix representing nested...

Description Usage Arguments Details Value See Also Examples

View source: R/zero_matrix_nest.R

Description

Create a structural zero matrix representing a situation where one set of categories is nested within another - eg counties within states, or detailed occupations within broad occupational categories.

Usage

1

Arguments

nest

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

Details

Nesting can be contrasted with crossing, where each set of categories are independent of the others, eg age vs sex.

nest is a data.frame providing a mapping between the higher-level categories and lower-level categories. nest has two columns: one with the higher-level categories, and one with the lower-level categories. Each row gives the higher-level category associated with a lower-level category. The order of the columns and rows does not matter.

Each lower-level category can belong to only one higher-level category.

zero_matrix_nest returns a logical matrix indicating whether each lower-level category nests within the corresponding higher-level category.

Value

A matrix of TRUEs and FALSEs, with dimnames constructed from nest.

See Also

Function add_dim_nest adds a dimension representing the higher-level categories to an array containing the lower-level categories.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
nest <- data.frame(region = c("Asia", "Africa", "Africa"),
                   country = c("India", "Nigeria", "Zimbabwe"))
zero_matrix_nest(nest)

nest <- data.frame(level2 = c("Bacterial infections",
                              "Viral infections",
                              "Infections caused by fungi",
                              "Lip, oral cavity, pharynx",
                              "Digestive organs"),
                   level1 = c("Infectious and parasitic diseases",
                              "Infectious and parasitic diseases",
                              "Infectious and parasitic diseases",
                              "Neoplasms",
                              "Neoplasms"))
zero_matrix_nest(nest)

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