Search code examples
rforecasting

Time Series hourly data format


From the data bellow I'm trying to create a time series object with zoo package

 head(data)                            MTU    Fossil
1 01.01.2015 00:00 - 01.01.2015 01:00 (CET)   2805
2 01.01.2015 01:00 - 01.01.2015 02:00 (CET)   2714
3 01.01.2015 02:00 - 01.01.2015 03:00 (CET)   2694
4 01.01.2015 03:00 - 01.01.2015 04:00 (CET)   2563
5 01.01.2015 04:00 - 01.01.2015 05:00 (CET)   2381
6 01.01.2015 05:00 - 01.01.2015 06:00 (CET)   2438

Solution

  • Pick a time for the time series (depends on your application), could be the start, end or midpoint of the time range.

    a$starttime=substr(a$MTU,1,16)
    

    Write out a data frame with the correctly typed information

    out = data.frame(times = strptime(a$starttime, format="%m.%d.%Y %H:%M", tz="CET"), Fossil=a$Fossil)
    

    Convert to ts object or zoo object using your favorite method.