sum_bilat | R Documentation |
Summary of bilateral flows, counter-flow and net migration flow
sum_bilat(m, label = "flow", orig = "orig", dest = "dest", flow = "flow")
m |
A |
label |
Character string for the prefix of the calculated columns. Can take values |
orig |
Character string of the origin column name (when |
dest |
Character string of the destination column name (when |
flow |
Character string of the flow column name (when |
A tibble
with columns for orig, destination, corridor, flow, counter-flow and net flow in each bilateral pair.
# 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()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.