counts-values-generator: Create objects of class "Counts" or "Values".

Description Usage Arguments Details Value See Also Examples

Description

Create objects of class Counts or Values from an array-like object with a full set of dimnames.

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
Counts(object, dimtypes = NULL, dimscales = NULL)

Values(object, dimtypes = NULL, dimscales = NULL)

## S4 method for signature 'array'
Counts(object, dimtypes = NULL, dimscales = NULL)

## S4 method for signature 'numeric'
Counts(object, dimtypes = NULL, dimscales = NULL)

## S4 method for signature 'ANY'
Counts(object, dimtypes = NULL, dimscales = NULL)

## S4 method for signature 'DemographicArray'
Counts(object, dimtypes = NULL, dimscales = NULL)

## S4 method for signature 'array'
Values(object, dimtypes = NULL, dimscales = NULL)

## S4 method for signature 'numeric'
Values(object, dimtypes = NULL, dimscales = NULL)

## S4 method for signature 'ANY'
Values(object, dimtypes = NULL, dimscales = NULL)

## S4 method for signature 'DemographicArray'
Values(object, dimtypes = NULL, dimscales = NULL)

Arguments

object

An array, an array-like object such as a table, or a vector. The object must have a full set of names and dimnames (see below for details.)

dimtypes

A named character vector describing the dimtypes of one or more dimensions.

dimscales

A named character vector describing the dimscales of one or more dimensions.

Details

A full set of dimnames means that dimnames(object) is a named list with no NAs or (unless the dimension has length 0) NULLs. In addition, within each dimension there should be no repeated dimnames.

If the dimnames for a dimension look like labels for points or intervals, but are not in numeric order, then Counts and Values will permute rows to put them in order. The most common reason for having interval labels out of order is that xtabs has sorted them lexicographically. See below for an example.

Functions Counts and Values infer dimtypes and dimscales from dimnames(object), plus the dimtypes and dimscales arguments, if supplied. Some ways to assist this process are:

Value

An object of class Counts or Values.

See Also

Counts, Values, 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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
a <- array(rpois(n = 8, lambda = 10),
          dim = c(2, 2, 2),
          dimnames = list(age = c("0-39", "40+"),
                          sex = c("Female", "Male"),
                          year = c("2001-2010", "2011-2020")))
a
Counts(a)
names(dimnames(a)) <- c("aGe", "SEX", "perioD")
Counts(a)

a <- array(rnorm(n = 5), dim = 5, dimnames = list(age = 0:4))
a
Values(a)
Values(a, dimscales = c(age = "Points"))

Counts(occupationalStatus)

Titanic
## Not run: Counts(Titanic) ## fails
## 'Counts' assumes that the dimension called "Age"
## has dimtype "age", but is then unable to derive
## "Points" or "Intervals" dimscales from categories
## "Child" and "Adult".

## One solution is to rename the "Age" dimension
## to something that Counts does not recognize
## as an age group
Titanic2 <- Titanic
names(dimnames(Titanic2))[3] <- "AgeGp"
Counts(Titanic2)

## A better solution is to explicitly set the dimtypes
Counts(Titanic, dimtypes = c(Age = "state"))

## DemographicArray objects can be created from numeric vectors,
## provided that the vectors have enough names
births <- c(Males = 105, Females = 100)
Counts(births)

## 'xtabs' gets the labels in the wrong order,
## but 'Counts' put them back into the right order
d <- data.frame(age = c("0-4", "5-9", "10+", "0-4", "5-9", "10+"),
                sex = c("F", "F", "F", "M", "M", "M"),
                count = 1:6)
xt <- xtabs(count ~ age + sex, data = d)
x <- Counts(xt)

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