sum_bilat: Summary of bilateral flows, counter-flow and net migration...

View source: R/sum_bilat.R

sum_bilatR 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 = "orig", dest = "dest", flow = "flow")

Arguments

m

A matrix or data frame of origin-destination flows. For matrix the first and second dimensions correspond to origin and destination respectively. For a data frame ensure the correct column names are passed to orig, dest and flow.

label

Character string for the prefix of the calculated columns. Can take values flow or stream

orig

Character string of the origin column name (when m is a data frame rather than a matrix)

dest

Character string of the destination column name (when m is a data frame rather than a matrix)

flow

Character string of the flow column name (when m is a data frame rather than a matrix)

Value

A tibble with columns for orig, destination, corridor, flow, counter-flow and net flow in each bilateral pair.

Examples

# using 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)

# using 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

# orig-dest summary of sex-specific flows
d %>%
  group_by(sex) %>%
  sum_bilat()

# use group_by to distinguish orig-dest tables
d %>%
  group_by(sex) %>%
  sum_bilat()

gjabel/migest documentation built on Feb. 10, 2025, 12:39 p.m.