slab: Extract or replace a slab from a demographic array.

Description Usage Arguments Details See Also Examples

Description

Extract a slab length(elements) thick from object, perpendicular to the dimension specified by dimension, or replace the current values of the slab with new values

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
slab(object, dimension, elements, drop = TRUE)

slab(object, dimension, elements, drop = TRUE) <- value

## S4 method for signature 'Component'
slab(object, dimension, elements, drop = TRUE)

## S4 method for signature 'Births'
slab(object, dimension, elements, drop = TRUE)

## S4 method for signature 'InternalMovementsPool'
slab(object, dimension, elements, drop = TRUE)

## S4 method for signature 'InternalMovementsNet'
slab(object, dimension, elements, drop = TRUE)

## S4 method for signature 'DemographicArray'
slab(object, dimension, elements, drop = TRUE)

## S4 replacement method for signature 'DemographicArray'
slab(object, dimension, elements, drop = TRUE) <- value

Arguments

object

Object of class DemographicArray.

dimension

Name or index of dimension.

elements

Labels or indices of elements with in dimension.

drop

TRUE, FALSE, or the word "dimension" (possibly abbreviated). Defaults to TRUE. result.

value

An numeric vector, or an object that can be coerced to a numeric vector.

Details

slab is designed for programming, in situations where the dimension of an object is not fixed in advance (which makes [ inconvenient). In interactive use, subarray may be a better choice, as it is clearer and more flexible.

When drop is set to TRUE or FALSE, it works exactly like the drop argument in standard R extract functions (eg Extract. If drop is TRUE, then all length-one dimensions in the return value are removed; if drop is FALSE, then all length-one dimensions are preserved. slab, however, has a third option, the word "dimension". In this case the only dimension eligible for dropping if it is length one is the dimension specified by the dimension argument. See below for an example. Note that the word "dimension" can be abbreviated.

The replacement method ignores any attributes attached to code such as dimensions or dimnames. In particular, if value is a DemographicArray object, any metadata is ignored.

See Also

subarray, [

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
library(demdata)
x <- Values(VADeaths2)
x
slab(x, dimension = "age", elements = 1:3)
slab(x, dimension = 1, elements = 1:3)
slab(x, dimension = "age", elements = c("50-54", "70-74"))
slab(x, dimension = "sex", elements = 1)
slab(x, dimension = "sex", elements = 1, drop = FALSE)

slab(x, dimension = "sex", elements = "Male") <- 999
x
slab(x, dimension = "age", elements = "50-54") <- 1:4
x

x1 <- slab(x, dimension = "age", elements = 1, drop = FALSE)
x1
## drop length-one "sex" and "age" dimensions:
slab(x1, dimension = "sex", elements = "Male", drop = TRUE)
## don't drop any length-one dimensions:
slab(x1, dimension = "sex", elements = "Male", drop = FALSE)
## only drop the length-one "sex" dimension:
slab(x1, dimension = "sex", elements = "Male", drop = "dimension")
## abbreviate "dimension"
slab(x1, dimension = "sex", elements = "Male", drop = "dim")

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