Learn R Programming

quadkeyr (version 0.1.0)

apply_weekly_lag: Apply a 7 day lag to the variable n_crisis

Description

Applying a week lag to the data will create raster images showing the mobility a week before the date of interest. This function works only for QuadKeys reported without NAs for n_crisis and percent_change variables .

Usage

apply_weekly_lag(data)

Value

A data.frame with the extra columns n_crisis_lag_7 and percent_change_7.

  • n_crisis_lag_7, is the same variable defined as n_crisis in the Facebook mobility data.frame with a 7 day lag applied.

  • percent_change_7 is the difference between the n_crisis value between weeks expressed as percentage.

Arguments

data

A data.frame with the columns quadkey, day, hour and n_crisis.

Examples

Run this code

files <- read_fb_mobility_files(
  path_to_csvs = paste0(system.file("extdata",
    package = "quadkeyr"
  ), "/"),
  colnames = c(
    "lat",
    "lon",
    "quadkey",
    "date_time",
    "n_crisis",
    "percent_change"
  ),
  coltypes = list(
    lat = "d",
    lon = "d",
    quadkey = "c",
    date_time = "T",
    n_crisis = "c",
    percent_change = "c"
  )
)

apply_weekly_lag(data = files)

Run the code above in your browser using DataLab