Reputation: 1
I have a large dataset (temp) with measurements every ten minutes over several years. The column "value" also contains NAs. How can I create a proper timeseries-object? I tried to use the ts () function but I just did not manage to find out which frequency would fit my data set. I want to do correlation and analysation od trends / periodicity / seasonality afterwards.
> dput(head(temp))
structure(list(TS = structure(c(874659600, 874660200, 874660800,
874661400, 874662000, 874662600), class = c("POSIXct", "POSIXt"
), tzone = "UTC"), value = c(2.77268641140869, 2.77268641140869,
2.77268641140869, 2.77268641140869, 2.71474135464008, 2.71474135464008
)), row.names = c(NA, 6L), class = "data.frame")
Upvotes: 0
Views: 44
Reputation: 610
If you need to change frequency, you need to decide it yourself or according to existing cases. You can use na.approx()
from zoo
package to interpolate 'value' and get rid of NAs.
#if we change the frequency to 1 minute
temp%<>%merge(data.frame('TS' =seq(min(temp$TS), max(temp$TS), by = '1 min')), all=T)
temp$value = zoo::na.approx(temp$value)
TS value
1 1997-09-19 09:00:00 2.772686
2 1997-09-19 09:01:00 2.772686
3 1997-09-19 09:02:00 2.772686
4 1997-09-19 09:03:00 2.772686
5 1997-09-19 09:04:00 2.772686
6 1997-09-19 09:05:00 2.772686
7 1997-09-19 09:06:00 2.772686
8 1997-09-19 09:07:00 2.772686
9 1997-09-19 09:08:00 2.772686
10 1997-09-19 09:09:00 2.772686
...
31 1997-09-19 09:30:00 2.772686
32 1997-09-19 09:31:00 2.766892
33 1997-09-19 09:32:00 2.761097
34 1997-09-19 09:33:00 2.755303
35 1997-09-19 09:34:00 2.749508
36 1997-09-19 09:35:00 2.743714
37 1997-09-19 09:36:00 2.737919
38 1997-09-19 09:37:00 2.732125
39 1997-09-19 09:38:00 2.726330
40 1997-09-19 09:39:00 2.720536
41 1997-09-19 09:40:00 2.714741
42 1997-09-19 09:41:00 2.714741
43 1997-09-19 09:42:00 2.714741
44 1997-09-19 09:43:00 2.714741
45 1997-09-19 09:44:00 2.714741
46 1997-09-19 09:45:00 2.714741
47 1997-09-19 09:46:00 2.714741
48 1997-09-19 09:47:00 2.714741
49 1997-09-19 09:48:00 2.714741
50 1997-09-19 09:49:00 2.714741
51 1997-09-19 09:50:00 2.714741
Upvotes: 0