addMissingDates: Adds missing dates to wide data

Description Usage Arguments Examples

View source: R/addMissingDates.R

Description

Adds rows with 0 values to a wide table that doesn't have consecutive dates

Usage

1
2
addMissingDates(x, date.index = "Week", start.date = NULL,
  end.date = NULL, data.frequency = 7)

Arguments

x

data.table. In wide format.

date.index

Character. The column in x that is the date variable.

start.date

Character in "yyyy-mm-dd" format. The first date of the required output, if NULL, function takes the min of date.index.

end.date

Character in "yyyy-mm-dd" format. The last date of the required output, if NULL, function takes the max of date.index.

data.frequency

Integer. Number of days that each row should cover, 1 = one day, 7 = one week.

Examples

1
2
3
4
5
x <- data.table::fread(system.file("extdata", "Newspapers.csv", package = "nladwa"))
x$Date <- as.Date(x$Date)
print(x) # missing 2015-01-03, 05, 06, 07, 08, 09
addMissingDates(x = x, date.index = "Date", data.frequency = 1) # now has them all
addMissingDates(x = x, date.index = "Date", data.frequency = 1, start.date = "2014-12-01")

Braja93/braja documentation built on June 1, 2017, 5:19 p.m.