r <- LETTERS[1:4]
m <- matrix(data = c(0, 100, 30, 10, 50, 0, 50, 5, 10, 40, 0, 40, 20, 25, 20, 0),
nrow = 4, ncol = 4, dimnames = list(orig = r, dest = r), byrow = TRUE)
m
# threshold on in and out region
sum_lump(m, threshold = 100, lump = c("in", "out"))
# threshold on flows (default)
sum_lump(m, threshold = 40)
# return a matrix (only possible when input is a matrix and
# complete = TRUE) with small values replaced by zeros
sum_lump(m, threshold = 50, complete = TRUE)
# return a data frame with small values replaced with zero
sum_lump(m, threshold = 80, complete = TRUE, return_matrix = FALSE)
if (FALSE) {
# data frame (tidy) format
library(tidyverse)
# download Abel and Cohen (2019) estimates
f <- read_csv("https://ndownloader.figshare.com/files/38016762", show_col_types = FALSE)
f
# large 1990-1995 flow estimates
f %>%
filter(year0 == 1990) %>%
sum_lump(flow_col = "da_pb_closed", threshold = 1e5)
# large flow estimates for each year
f %>%
group_by(year0) %>%
sum_lump(flow_col = "da_pb_closed", threshold = 1e5)
}
Run the code above in your browser using DataLab