sum_turnover: Extract total in-, out- and net-migration totals from an...

Description Usage Arguments Value Examples

View source: R/sum_turnover.R

Description

Extract total in-, out- and net-migration totals from an origin-destination migration flow matrix or data frame.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
sum_turnover(
  m,
  drop_diagonal = TRUE,
  include_net = TRUE,
  orig_col = "orig",
  dest_col = "dest",
  flow_col = "flow",
  type = "internal",
  international = FALSE,
  name_tot = FALSE
)

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_col, dest_col and flow_col.

drop_diagonal

Logical to indicate dropping of diagonal terms, where the origin and destination are the same, in the calculation of totals. Default TRUE.

include_net

Logical to indicate inclusion of a net migration total column for each region, in addition to the total in- and out-flows. Default TRUE.

orig_col

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

dest_col

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

flow_col

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

type

Character string to indicate if flows are internal or international to indicate if to use region, tot_in_mig, tot_out_mig or country, tot_imm and tot_emi in output.

international

Logical to indicate if flows are international.

name_tot

Logical to prefix column names with "tot_". Default 'FALSE'.

Value

A tibble with total in-, out- and turnover of flows for each region.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# matrix
dn <- 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 = dn, dest = dn), byrow = TRUE)
sum_turnover(m)
  
# different labels
sum_turnover(m, international = TRUE)

## Not run: 
# data frame (tidy) format
library(tidyverse)

# download Abel and Cohen (2019) estimates
f <- read_csv("https://ndownloader.figshare.com/files/26239945")

# turnover for single period
f %>% 
  filter(year0 == 1990) %>%
  sum_turnover(flow_col = "da_pb_closed", type = "international")

# turnover for all periods using group_by
f %>% 
  group_by(year0) %>%
  sum_turnover(flow_col = "da_pb_closed", type = "international")

## End(Not run)   

migest documentation built on July 25, 2021, 9:07 a.m.