statar (version 0.4.0)

is.panel: Check whether data.table is a panel data

Description

Check whether data.table is a panel data

Usage

is.panel(x, ...)

is.panel_(x, vars)

setpanel(x, ...)

setpanel_(x, vars)

Arguments

x
a vector or matrix
...
id variables. Last is time variable
vars
Used to work around non standard evaluation

Value

  • The function is.panel checks no data variable is missing and that there are no duplicates for (id, along_with). The function setpanel reorders data.table in place if is.panel is TRUE

Examples

Run this code
library(data.table)
DT <- data.table(
    id    = c(1, 1, 1, 2, 2),
    year  = c(1991, 1993, NA, 1992, 1992),
    value = c(4.1, 4.5, 3.3, 3.2, 5.2)
)
is.panel(DT, id, year)
DT <- na.omit(DT, cols = "year")
is.panel(DT, id, year)
DT <- unique(DT, by = c("id", "year"))
is.panel(DT, id, year)
setpanel(DT, id, year)

Run the code above in your browser using DataLab