collapseCategories: Collapse multiple categories into a single category.

Description Usage Arguments Details See Also Examples

Description

Merge multiple categories within a dimension or dimensions of a DemographicArray object.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
collapseCategories(
  object,
  dimension = NULL,
  old,
  new,
  concordance,
  weights = NULL,
  ...
)

## S4 method for signature 'Counts,ANY,ANY,ANY,missing'
collapseCategories(object, dimension = NULL, old, new, weights = NULL)

## S4 method for signature 'Counts,ANY,missing,missing,OneToOne'
collapseCategories(object, dimension = NULL, concordance, weights = NULL)

## S4 method for signature 'Counts,ANY,missing,missing,ManyToOne'
collapseCategories(object, dimension = NULL, concordance, weights = NULL)

## S4 method for signature 'Values,ANY,ANY,ANY,missing'
collapseCategories(object, dimension, old, new, weights)

## S4 method for signature 'Values,ANY,missing,missing,ManyToOne'
collapseCategories(object, dimension, concordance, weights)

## S4 method for signature 'Values,ANY,missing,missing,OneToOne'
collapseCategories(object, dimension = NULL, concordance, weights = NULL)

Arguments

object

Object of class DemographicArray.

dimension

Character or numeric vector giving the name or index of the dimension where the categories are found - or names or indices if more than one dimension is being changed.

old

Character vector containing the names of the categories to be collapsed.

new

Character vector of length 1 giving the name of the new category formed from the old categories.

concordance

Object of class "Concordance".

weights

Object of class Counts.

...

Not currently used.

Details

The categories to be collapsed, and the categories that result from collapsing can be described through old and new, or through a "ManyToOne" concordance: see below for examples.

Pairs of of dimensions with dimtypes origin and destination or parent and child can be selected by their base name: see the example below. If no dimension is supplied, collapseCategories attempts to modify all dimensions.

weights are required if object has class Values and are prohibited if object has class Counts.

See Also

collapseIntervals, collapseIterations, collapseOrigDest, collapseDimension, dimtypes, dimscales

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
titanic <- Counts(Titanic, dimtypes = c(Age = "state"))
collapseCategories(titanic, dimension = "Class",
                   old = c("1st", "2nd", "3rd"),
                   new = "Passengers")
## can also use the dimension index, though the name is clearer
collapseCategories(titanic, dimension = 1,
                   old = c("1st", "2nd", "3rd"),
                   new = "Passengers")
## set up and use a concordance
conc <- data.frame(status = c("1st", "2nd", "3rd", "Crew"),
                   wealth = c("Rich", "Mixed", "Poor", "Mixed"))
conc <- Concordance(conc)
collapseCategories(titanic, dimension = "Class", concordance = conc)

library(demdata)
rates <- Values(VADeaths2)
popn <- Counts(VAPopn)
collapseCategories(rates, dimension = "sex", old = c("Male", "Female"),
                   new = "Combined", weights = popn)

occ <- occupationalStatus
names(dimnames(occ)) <- c("occupation_parent", "occupation_child")
occ <- Counts(occ)
## select a pair of dimensions by specifying a base name
collapseCategories(occ, dimension = "occupation",
                   old = c("2", "5"), new = "9")
## no dimension specified, so changes made to all dimensions
collapseCategories(occ, old = c("2", "5"), new = "9")

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