sum_bilat {migest} | R Documentation |
Summary of bilateral flows, counter-flow and net migration flow
Description
Summary of bilateral flows, counter-flow and net migration flow
Usage
sum_bilat(
m,
label = "flow",
orig_col = "orig",
dest_col = "dest",
flow_col = "flow"
)
Arguments
m |
A |
label |
Character string for the prefix of the calculated columns. Can take values |
orig_col |
Character string of the origin column name (when |
dest_col |
Character string of the destination column name (when |
flow_col |
Character string of the flow column name (when |
Value
A tibble
with columns for orig, destination, corridor, flow, counter-flow and net flow in each bilateral pair.
Examples
# matrix
r <- LETTERS[1:4]
m <- matrix(data = c(0, 100, 30, 70, 50, 0, 45, 5, 60, 35, 0, 40, 20, 25, 20, 0),
nrow = 4, ncol = 4, dimnames = list(orig = r, dest = r), byrow = TRUE)
m
sum_bilat(m)
# data frame
library(dplyr)
library(tidyr)
d <- expand_grid(orig = r, dest = r, sex = c("female", "male")) %>%
mutate(flow = sample(x = 1:100, size = 32))
d
# use group_by to distinguish od tables
d %>%
group_by(sex) %>%
sum_bilat()