mp_interpolate: Interpolate values within election periods

Description Usage Arguments Examples

View source: R/dataset.R

Description

As the Manifesto Project's variables are collected election-wise, values for the time/years in between elections are not naturally available. mp_interpolate allows to approximate them by several methods from the abjacent observations.

Usage

1
2
3
4
5
6
7
mp_interpolate(
  df,
  vars = "(^rile$)|(^per((\\d{3}(_\\d)?)|\\d{4})$)",
  by = "year",
  approx = zoo::na.approx,
  ...
)

Arguments

df

a data.frame with observations to be interpolated

vars

a regular expression matching the names of the variables to be interpolated

by

increment of the interpolation sequence, passed to seq.Date

approx

Interpolation function, defaults to zoo's na.approx

...

Further arguments, passed on to approx

Examples

1
2
3
4
5
## Not run: 
mp_interpolate(mp_maindataset(), method = "constant")
mp_interpolate(mp_maindataset(), approx = na.spline, maxgap = 3)

## End(Not run)

manifestoR documentation built on Jan. 13, 2021, 9:53 a.m.