balPanel: Create balanced panel dataset

Description Usage Arguments Details Value Examples

Description

Takes an unbalanced panel dataset and makes it balanced by inserting rows for missing time periods and initializing with NAs for other columns that are not the time or individual variable.

Usage

1
balPanel(df, datev, id, freq = "month")

Arguments

df

data.frame of unbalanced panel data

datev

name of data variable in data.frame df

id

name of individual/entity variable. Company ID, country or people's names, for example.

freq

desired frequency of the time-series'

Details

Doesn't have any special treatment for duplicate values in the input time panel dataset. Currently handles time/date objects of type "Date" or "numeric". Can add POSIX and other date/time classes as needed.

Value

balanced panel dataset as a data.frame. Values for dates that are missing in the input dataset show up as NAs

Examples

1
2
3
4
5
df <- data.frame(date=sort(sample(seq(Sys.Date()-20, Sys.Date(), by=1), 30, replace=T)),
                x1=runif(30),
                id=rep(c('A', 'B', 'C'), 10), stringsAsFactors=F)

balPanel(df, datev='date', id='id', freq='days')

brooksandrew/Rsenal documentation built on May 13, 2019, 7:50 a.m.