Description Usage Arguments Details Value See Also Examples
Aggregate values along one or more dimensions of an object of class
DemographicArray
. The aggregated
dimensions are dropped.
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 | collapseDimension(
object,
dimension = NULL,
margin = NULL,
weights,
na.rm = FALSE,
...
)
## S4 method for signature 'Pool,ANY,ANY,missing'
collapseDimension(object, dimension = NULL, margin = NULL, weights)
## S4 method for signature 'Counts,ANY,ANY,missing'
collapseDimension(
object,
dimension = NULL,
margin = NULL,
weights,
na.rm = FALSE
)
## S4 method for signature 'Counts,ANY,ANY,Counts'
collapseDimension(
object,
dimension = NULL,
margin = NULL,
weights,
na.rm = FALSE
)
## S4 method for signature 'Values,ANY,ANY,ANY'
collapseDimension(
object,
dimension = NULL,
margin = NULL,
weights,
na.rm = FALSE
)
## S4 method for signature 'Values,ANY,ANY,missing'
collapseDimension(object, dimension = NULL, margin = NULL, na.rm = FALSE)
|
object |
An object of class |
dimension |
Names or indices of the dimensions to be collapsed. |
margin |
Names or indices of the dimensions that will remain after the collapsing. |
weights |
Object of class |
na.rm |
A logical value indicating whether NA values should be stripped before the computation proceeds. |
... |
Not currently used. |
Either dimension
or margin
must be supplied, but not both.
weights
are required if object
has class
Values
, and prohibited if object
has class
Counts
.
If all dimensions are collapsed, the result is equivalent to
sum(object)
.
As discussed in dimtypes
, some dimensions come in pairs.
Members of a pair have the same base name but different suffixes, e.g.
"region_orig"
and "region_dest"
. Including the base name,
e.g. "region"
, in the dimension
or margin
arguments has
the same effect as including both names. If only one member of a pair of
dimensions is collapsed, the suffix is removed and from the name of the
remaining dimension, and the dimtype is changed to "state"
. See
below for examples.
An object of the same class as object
, but with fewer
dimensions, or a single number.
addDimension
, collapseCategories
,
collapseIntervals
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)
## collapse Counts object
popn <- Counts(VAPopn)
popn
collapseDimension(popn, dimension = "age")
collapseDimension(popn, dimension = c("sex", "color"))
collapseDimension(popn, margin = c("sex", "color"))
## collapse Values object, supplying weights
rate <- Values(VADeaths2)
collapseDimension(rate, dimension = "age", weights = popn)
## special treatment of origin-destination dimensions
mig <- Counts(nz.mig)
mig
collapseDimension(mig, dimension = "island")
collapseDimension(mig, margin = "island")
## note dimension name and dimtype:
collapseDimension(mig, margin = "island_orig")
## collapse all dimensions
popn <- Counts(VAPopn)
collapseDimension(popn, dimension = c("age", "sex", "residence"))
collapseDimension(popn, margin = character())
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.