panel_lead: Tidy panel leading

Description Usage Arguments Details Value Examples

View source: R/lead_panel.R

Description

Efficient, tidy panel leading

Usage

1
2
panel_lead(data, cross.section, time.variable = NULL, leads = 1,
  variables.selected = NULL, keep.original = TRUE)

Arguments

data

The data input, anything coercible to a data.table.

cross.section

The cross section argument, see examples.

time.variable

The variable to indicate time in your panel. Defaults to NULL, though it is recommended to have a time variable.

leads

The leads to use in panel leading.

variables.selected

A variable selection for variables to lead, defaults to NULL and leads ALL variables.

keep.original

Whether to keep the original unleadged data, defaults to TRUE.

Details

Works on a full data.table backend for maximum speed wherever possible.

Value

The leading data.table which contains either only the leading variables, or also the original variables.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
X <- matrix(rnorm(4000),800,5)
tim <- seq(1:400)
geo_AT <- rep(c("AT"), length = 400)
geo_NO <- rep(c("NO"), length = 400)
both_vec_1 <- cbind(tim,geo_NO)
both_vec_2 <- cbind(tim,geo_AT)
both <- rbind(both_vec_1,both_vec_2)
names(both[,"geo_NO"]) <- "geo"
X <- cbind(both,X)

panel_lead(data = X,
          cross.section = "geo_NO",
          time.variable = "tim",
          leads = 5,
          variables.selected = c("V5","tim", "V7"),
          keep.original = TRUE)

panelWranglR documentation built on Oct. 3, 2019, 9:03 a.m.