Reputation: 1704
I have a data file containing the raw values of my measurments. The top entries look like that:
495.08
1117.728
872.712
665.632
713.296
1172.44
1302.544
1428.832
1413.536
1361.896
1126.656
644.776
1251.616
1252.824
[...]
The measurements are done in 15 min intervals. In order to put this in a R time series object I use the following code.
data <- scan("./data__2.dat",skip=1)
datats <- ts(data, frequency=24*60/15, start=c(2014,1))
But this leaves me with:
Although the data is only from one year. Hence, it seems like the frequency is wrong. Any thoughts on how to fix this?
Upvotes: 1
Views: 4549
Reputation: 21621
By doing:
library(xts)
library(lubridate)
df <- data.frame(interval = seq(ymd_hms('2014-01-21 00:00:00'),
by = '15 min',length.out=(60*24*365/15)),
data = rnorm(60*24*365/15))
ts <- xts(df, order.by=df$interval)
You get:
interval data
1 2014-01-21 00:00:00 -1.3975823
2 2014-01-21 00:15:00 -0.4710713
3 2014-01-21 00:30:00 0.9149273
4 2014-01-21 00:45:00 -0.3053136
5 2014-01-21 01:00:00 -1.2459707
6 2014-01-21 01:15:00 0.4749215
Upvotes: 3