Having issues using Pad function to fill in date with time gaps – using R

I am having issues using the Pad function (Padr) to fill in gaps within a time series. I have some code that downloads hourly data from a server, one day at a time for a specific time period. After each day of data has been downloaded the aim is to use pad to clear up the data and add in the time and date so it can be appropriately combined without an error.

The function downloads the data as a list and looks like the following:

 time                  temperature
2019-11-11 00:00:00          3
2019-11-11 01:00:00          4 
2019-11-11 03:00:00          5

Would like a program to automatically fill in to look like below:

 time                  temperature
2019-11-11 00:00:00          3
2019-11-11 01:00:00          4 
2019-11-11 02:00:00          NA
2019-11-11 03:00:00          5

I have used PAD in the code below to fill in the gaps, but if the data starts at 02:00:00, it starts at that timestep. When using the start_val and end_val it seems to have problems recognising the date and time, any help would be appreciated. I have tried a lot of work arounds but no luck. Baring in mind the date will be different and there is no way of knowing which hour is missing.

    if (nrow(daily$hourly) < 24) {
    daily$hourly <- daily$hourly %>% pad(daily$hourly$time, start_val = as.POSIXct('00:00:00'),end_val = as.POSIXct('23:00:00') %>% fill_by_value(value)
  }

Leave a Reply

Your email address will not be published. Required fields are marked *