I load data.tablefrom a CSV file with fields of date, orders, quantity, etc.
The input file sometimes does not have data for all dates. For example, as shown below:
> NADayWiseOrders
date orders amount guests
1: 2013-01-01 50 2272.55 149
2: 2013-01-02 3 64.04 4
3: 2013-01-04 1 18.81 0
4: 2013-01-05 2 77.62 0
5: 2013-01-07 2 35.82 2
In the above 03 Jan and Jan 6 No records.
I would like to fill in the missing entries with default values ββ(for example, zero for orders, amounts, etc.) or transfer the last transfer (for example, Jan 03, will reuse the values ββJan 02, and 06 Jan will reuse 05- Jan. Values, etc.)
What is the best / best way to fill in such missing date spaces with such default values?
The answer here proposes to use allow.cartesian = TRUEand expand.gridfor missing work days - it can run on weekdays (since they are only 7 working days), but not sure if it was the right way to go on dates, especially if we are dealing with long-term data.
source
share