Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a time series of hourly data?

Tags:

r

time-series

I have data in an hourly values.

SNo Date       Hour     X
1   2006-12-17 00:00:00 1.8824667
2   2006-12-17 01:00:00 3.3494000
3   2006-12-17 02:00:00 1.5872667
4   2006-12-17 03:00:00 1.6622000
5   2006-12-17 04:00:00 2.2157667
6   2006-12-17 05:00:00 1.9967333
7   2006-12-17 06:00:00 1.3033000
8   2006-12-17 07:00:00 1.6200333
9   2006-12-17 08:00:00 1.8905667
10  2006-12-17 09:00:00 2.5490667
11  2006-12-17 10:00:00 3.6289000

How would I create a time series out of this? What would be the frequency and start/end parameters?

The last date & time is

2010-11-26 21:00:00

like image 600
carrotflowers Avatar asked Nov 18 '15 14:11

carrotflowers


1 Answers

Here's how to use the ts() function in base R (assuming your data X are contained in the data frame dat). You'll need to specify the first year and hour for start (you don't need end), and frequency will be the number of hours in a year.

firstHour <- 24*(as.Date("2006-12-17 00:00:00")-as.Date("2006-1-1 00:00:00"))
tt <- ts(dat$X,start=c(2006,firstHour),frequency=24*365)
like image 126
Mark S Avatar answered Oct 20 '22 16:10

Mark S