# 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()
Run the code above in your browser using DataLab