I'm working with time series data at 5-minute time intervals. Some of the 5-minute time series are missing. I'd like to resample the dataset to fill in the missing 5-minute periods with NaN values. I found great information on how to approach this here: R: Insert rows for missing dates/times.
I've created a data.frame "df" with a POSIXct timeseries column "time".
The pad function in the padr package allows a user to set an interval by the minute, hour, day, etc.
interval
The interval of the returned datetime variable. When NULL the the interval >will be equal to the interval of the datetime variable. When specified it can >only be lower than the interval of the input data. See Details.
padr's pad function will create 1-minute intervals on my 5-minute data. How do I set my own user-defined interval (e.g. 5-minutes)?
New version hit CRAN yesterday. You can now use units different from 1 in each of the intervals
library(padr)
library(dplyr)
coffee %>% thicken("5 min") %>% select(-time_stamp) %>% pad()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With