Learn R Programming

idmc (version 0.4.1)

idmc_transform_daily: Transform displacement event data to daily data

Description

idmc_transform_daily() transforms event data from the IDMC API (accessed through idmc_get_data()). For each event, identified by an event_id, potentially duplicated data is filtered out. If there are Recommended figure rows based on the role column, then only those are kept. If there are no recommended figures, then only the latest update to the event_id data is kept for each locations_coordinates, using created_at to find latest updates.

Usage

idmc_transform_daily(
  df,
  min_date = as.Date("2018-01-01"),
  max_date = Sys.Date(),
  filter_min_date = TRUE
)

Value

Data frame of daily displacement with the following columns:

iso3

Country ISO3 code.

country

Country or area name.

displacement_type

Type of displacement.

date

Date.

displacement_daily

Daily level of displacement.

Arguments

df

Event displacement data frame, generated from idmc_get_data().

min_date

Date to backfill displacement data to. By default, min_date is set the first day of 2018. Only a few observations of the IDMC data are from before 2018, spanning back to 2011. If NULL, no backfilling is done, and the first reported case in the IDMC database is taken as the earliest.

max_date

Date to extrapolate all data to, filling with 0. If the The latest date in the data frame is used if later than max_date. If NULL, no extrapolation is done.

filter_min_date

If TRUE, the default, filters the data to only contain data from min_date onward. Ensures that the few countries with observations from 2011 but nothing until 2018 do not skew results.

Details

The data for each event is spread out between the minimum start and maximum end date for each event?id, with the total displacement uniformly distributed across all days. For each country and displacement type (conflict, disaster, or other), all displacement on a day is summed up to create a total daily displacement figure.

By default, data is backfilled for all countries and displacement types to the first reported date in the IDMC dataset. Data is always infilled with 0 between start and end dates.

Examples

Run this code
if (FALSE) { # !is.na(Sys.getenv("IDMC_API", unset = NA))
idmc_get_data() %>%
  idmc_transform_daily()
}

Run the code above in your browser using DataLab