| collapseOrigDest {dembase} | R Documentation |
Convert data on movements classifed by state of origin and state of destination into a less detailed format. The choices of format are
"out"Total outward moves from each state
"in"Total inward moves to each state
"pool""out" and "in"
"net""in" minus "out"
collapseOrigDest(
object,
base = NULL,
to = c("net", "pool", "in", "out"),
weights,
omitted = ifelse(methods::is(object, "Counts"), 0L, NA_integer_),
...
)
## S4 method for signature 'Counts,ANY,ANY,missing'
collapseOrigDest(
object,
base = NULL,
to = c("net", "pool", "in", "out"),
omitted = ifelse(methods::is(object, "Counts"), 0L, NA_integer_)
)
## S4 method for signature 'Values,ANY,ANY,ANY'
collapseOrigDest(
object,
base = NULL,
to = c("net", "pool", "in", "out"),
weights,
omitted = ifelse(methods::is(object, "Counts"), 0L, NA_integer_)
)
object |
Object of class |
base |
Character vector giving the "base names" for the
origin-destination pairs. If |
to |
The new format(s): |
weights |
Object of class |
omitted |
Value to be used for omitted origin-destination or
parent-child combinations. Defaults to |
... |
Not currently used. |
collapseOrigDest calls function alignPair before
collapsing cells. Argument omitted is passed to alignPair.
If object has class linkS4class{Counts} and
to is "net", then the return value has class
Net. If object has class
linkS4class{Counts} and' to is "pool",
then the return value has class Pool.
Otherwise the return value has the same class as object.
If ans is the result of applying
collapseOrigDest to x, then sum(ans) does not
necessarily equal sum(x). For instance,
sum(collapseOrigDest(x, to = "net")) is always 0.
Wilson, T. and Bell, M. (2004) Comparative empirical evaluations of internal migration models in subnational population projections. Journal of Population Research. 21(2): 127-160.
alignPair collapseCategories,
collapseIntervals, collapseIterations,
collapseOrigDest, collapseDimension,
dimtypes, dimscales
library(demdata)
mig <- Counts(nz.mig)
collapseOrigDest(mig, base = "island", to = "net")
## base defaults to all origin-destination base names,
## and 'to' defaults to "net"
collapseOrigDest(mig)
## multiple formats, distinguished by dimension "direction"
collapseOrigDest(mig, to = "pool")
collapseOrigDest(mig, to = "net")
collapseOrigDest(mig, to = "out")
## different representations imply different totals
sum(mig)
sum(collapseOrigDest(mig, to = "net"))
sum(collapseOrigDest(mig, to = "pool"))
x <- Counts(array(1:4,
dim = c(2, 2),
dimnames = list(region_orig = c("a", "b"),
region_dest = c("c", "b"))))
x
## extra categories are added to region_orig and
## region_dest via 'alignPair' before collapsing
collapseOrigDest(x, to = "pool")