Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

padr in R: padding at user-defined interval

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)?

like image 499
Guy Avatar asked Jan 04 '23 10:01

Guy


1 Answers

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()
like image 85
Edwin Avatar answered Jan 07 '23 16:01

Edwin