From 201906141930 to "2019-16-14 19:30:00" - r

I've a data frame with a column dateHourMinute that I need it as POSIXct to make a plot.
For example this dateHourMinute 201906141930, I'd like to get: 2019-06-14 19:30:00 as a POSIXct element.
data:
structure(list(dateHourMinute = c("201906141930", "201906141931",
"201906141932", "201906141933", "201906141934", "201906141935",
"201906141936", "201906141937", "201906141938", "201906141939",
"201906141940", "201906141941", "201906141942", "201906141943",
"201906141944", "201906141945", "201906141946", "201906141947",
"201906141948", "201906141949", "201906141950", "201906141951",
"201906141952", "201906141953", "201906141954", "201906141955",
"201906141956", "201906141957", "201906141958", "201906141959",
"201906142000", "201906142001", "201906142002", "201906142003",
"201906142004", "201906142005", "201906142006", "201906142007",
"201906142008", "201906142009", "201906142010", "201906142011",
"201906142012", "201906142013", "201906142014", "201906142015",
"201906142016", "201906142017", "201906142018", "201906142019",
"201906142020", "201906142021", "201906142022", "201906142023",
"201906142024", "201906142025", "201906142026", "201906142027",
"201906142028", "201906142029", "201906142030", "201906142031",
"201906142032", "201906142033", "201906142034", "201906142035",
"201906142036", "201906142037", "201906142038", "201906142039",
"201906142040", "201906142041", "201906142042", "201906142043",
"201906142044", "201906142045", "201906142046", "201906142047",
"201906142048", "201906142049", "201906142050", "201906142051",
"201906142052", "201906142053", "201906142054", "201906142055",
"201906142056", "201906142057", "201906142058", "201906142059",
"201906142100", "201906142101", "201906142102", "201906142103",
"201906142104", "201906142105", "201906142106", "201906142107",
"201906142108", "201906142109", "201906142110", "201906142111",
"201906142112", "201906142113", "201906142114", "201906142115",
"201906142116", "201906142117", "201906142118", "201906142119",
"201906142120", "201906142121", "201906142122", "201906142123",
"201906142124", "201906142125", "201906142126", "201906142127",
"201906142128", "201906142129", "201906142130", "201906142131",
"201906142132", "201906142133", "201906142134", "201906142135",
"201906142136", "201906142137", "201906142138", "201906142139",
"201906142140", "201906142141", "201906142142", "201906142143",
"201906142144", "201906142145", "201906142146", "201906142147",
"201906142148", "201906142149", "201906142150", "201906142151",
"201906142152", "201906142153", "201906142154", "201906142155"
), users = c(2894, 2969, 3031, 2912, 2845, 2837, 2832, 2731,
2784, 2681, 2682, 2614, 2569, 2551, 2580, 2588, 2574, 2458, 2419,
2504, 2430, 2401, 2322, 2252, 2329, 2374, 2201, 2142, 2163, 2133,
2087, 2078, 2053, 2206, 2093, 2091, 2045, 2059, 1945, 1943, 1951,
1972, 1899, 1822, 1841, 1906, 1778, 2148, 3297, 2098, 1801, 1650,
1630, 1626, 1674, 1647, 1633, 1671, 1757, 1862, 1968, 2045, 2119,
2396, 2513, 2394, 2375, 2492, 2488, 2381, 2417, 2337, 2243, 2211,
1999, 2021, 2037, 2418, 2254, 2050, 2004, 1944, 1802, 1718, 1726,
1725, 1641, 1657, 1592, 1604, 1551, 1553, 1486, 1481, 1518, 1479,
1310, 1317, 1329, 1259, 1255, 1259, 1407, 1352, 1250, 1250, 1223,
1149, 1103, 1108, 1025, 1165, 1870, 1452, 1418, 1469, 1522, 1303,
1147, 1060, 1004, 1001, 1003, 983, 894, 870, 882, 863, 832, 790,
819, 732, 751, 752, 694, 692, 926, 862, 755, 736, 796, 803, 771,
869, 745, 709)), row.names = c(NA, -146L), totals = list(list(
users = "2016665")), minimums = list(list(users = "1")), maximums = list(
list(users = "11863")), isDataGolden = TRUE, rowCount = 2875L, class = "data.frame")

You could use :
df$dateHourMinute <- as.POSIXct(df$dateHourMinute,format = "%Y%m%d%H%M", tz = "UTC")
#Or with `strptime`
#df$dateHourMinute <- strptime(df$dateHourMinute, format = "%Y%m%d%H%M", tz = "UTC")
head(df)
# dateHourMinute users
#1 2019-06-14 19:30:00 2894
#2 2019-06-14 19:31:00 2969
#3 2019-06-14 19:32:00 3031
#4 2019-06-14 19:33:00 2912
#5 2019-06-14 19:34:00 2845
#6 2019-06-14 19:35:00 2837
Or with lubridate
df$dateHourMinute <- lubridate::ymd_hm(df$dateHourMinute))

Related

how to extract fitted values in a forecast model after multiple model simulations

This is my original df and fitted model
library(tsibble)
library(tibble)
library(ISOweek)
library(fable)
library(forecast)
library(fpp3)
library(dplyr)
library(tidyverse)
Original.df <- structure(list(YearWeek = c("201901", "201902", "201903", "201904",
"201905", "201906", "201907", "201908", "201909", "201910", "201911",
"201912", "201913", "201914", "201915", "201916", "201917", "201918",
"201919", "201920", "201921", "201922", "201923", "201924", "201925",
"201926", "201927", "201928", "201929", "201930", "201931", "201932",
"201933", "201934", "201935", "201936", "201937", "201938", "201939",
"201940", "201941", "201942", "201943", "201944", "201945", "201946",
"201947", "201948", "201949", "201950", "201951", "201952", "202001",
"202002", "202003", "202004", "202005", "202006", "202007", "202008",
"202009", "202010", "202011", "202012", "202013", "202014", "202015",
"202016", "202017", "202018", "202019", "202020", "202021", "202022",
"202023", "202024", "202025", "202026", "202027", "202028", "202029",
"202030", "202031", "202032", "202033", "202034", "202035", "202036",
"202037", "202038", "202039", "202040", "202041", "202042", "202043",
"202044", "202045", "202046", "202047", "202048", "202049", "202050",
"202051", "202052", "202053", "202101", "202102", "202103", "202104",
"202105", "202106", "202107", "202108", "202109", "202110", "202111",
"202112", "202113", "202114", "202115", "202116", "202117", "202118",
"202119", "202120", "202121", "202122", "202123", "202124", "202125",
"202126", "202127", "202128", "202129", "202130", "202131", "202132",
"202133", "202134", "202135", "202136", "202137", "202138", "202139",
"202140", "202141", "202142", "202143"), Shipment = c(418, 1442,
1115, 1203, 1192, 1353, 1191, 1411, 933, 1384, 1362, 1353, 1739,
1751, 1595, 1380, 1711, 2058, 1843, 1602, 2195, 2159, 2009, 1812,
2195, 1763, 821, 1892, 1781, 2071, 1789, 1789, 1732, 1384, 1435,
1247, 1839, 2034, 1963, 1599, 1596, 1548, 1084, 1350, 1856, 1882,
1979, 1021, 1311, 2031, 1547, 591, 724, 1535, 1268, 1021, 1269,
1763, 1275, 1411, 1847, 1379, 1606, 1473, 1180, 926, 800, 840,
1375, 1755, 1902, 1921, 1743, 1275, 1425, 1088, 1416, 1168, 842,
1185, 1570, 1435, 1209, 1470, 1368, 1926, 1233, 1189, 1245, 1465,
1226, 887, 1489, 1369, 1358, 1179, 1200, 1226, 1066, 823, 1913,
2308, 1842, 910, 794, 1098, 1557, 1417, 1851, 1876, 1010, 160,
1803, 1607, 1185, 1347, 1700, 981, 1191, 1058, 1464, 1513, 1333,
1169, 1294, 978, 962, 1254, 987, 1290, 758, 436, 579, 636, 614,
906, 982, 649, 564, 502, 274, 473, 506, 902, 639, 810, 398, 488
), Production = c(0, 198, 1436, 1055, 1396, 1330, 1460, 1628,
1513, 1673, 1737, 1274, 1726, 1591, 2094, 1411, 2009, 1909, 1759,
1693, 1748, 1455, 2078, 1717, 1737, 1886, 862, 1382, 1779, 1423,
1460, 1454, 1347, 1409, 1203, 1235, 1397, 1563, 1411, 1455, 1706,
688, 1446, 1336, 1618, 1404, 1759, 746, 1560, 1665, 1317, 0,
441, 1390, 1392, 1180, 1477, 1265, 1485, 1495, 1543, 1584, 1575,
1609, 1233, 1420, 908, 1008, 1586, 1392, 1385, 1259, 1010, 973,
1053, 905, 1101, 1196, 891, 1033, 925, 889, 1136, 1058, 1179,
1047, 967, 900, 904, 986, 1014, 945, 1030, 1066, 1191, 1143,
1292, 574, 1174, 515, 1296, 1315, 1241, 0, 0, 1182, 1052, 1107,
1207, 1254, 1055, 258, 1471, 1344, 1353, 1265, 1444, 791, 1397,
1186, 1264, 1032, 949, 1059, 954, 798, 956, 1074, 1136, 1209,
975, 833, 994, 1127, 1153, 1202, 1234, 1336, 1484, 1515, 1151,
1175, 976, 1135, 1272, 869, 1900, 1173), Net.Production.Qty = c(22,
188, 1428, 1031, 1382, 1368, 1456, 1578, 1463, 1583, 1699, 1318,
1582, 1537, 2118, 1567, 1961, 1897, 1767, 1603, 1666, 1419, 2186,
1621, 1677, 1840, 698, 1290, 1411, 927, 1754, 1222, 1411, 1549,
1491, 1359, 1179, 1945, 1463, 1465, 1764, 764, 810, 1308, 1830,
1542, 1695, 544, 1482, 1673, 1659, 0, 445, 1358, 1364, 1224,
1417, 1239, 1387, 1595, 1469, 1624, 1643, 1763, 1217, 1456, 568,
1290, 1666, 1428, 1327, 773, 1118, 1231, 1143, 921, 1083, 1124,
935, 903, 937, 849, 1132, 1032, 1143, 1081, 891, 886, 880, 1002,
1072, 969, 1000, 996, 1243, 1183, 1306, 650, 1226, 553, 1306,
1379, 1359, 0, 0, 1182, 988, 1099, 1173, 1244, 1039, 254, 1425,
1318, 1385, 1221, 1364, 739, 1397, 1112, 1160, 924, 971, 1015,
978, 828, 868, 994, 1090, 1165, 783, 887, 934, 1023, 1045, 1114,
1052, 1186, 1456, 1401, 1249, 779, 430, 1625, 1498, 883, 1860,
1101), isoweek = c("2019-W01-1", "2019-W02-1", "2019-W03-1",
"2019-W04-1", "2019-W05-1", "2019-W06-1", "2019-W07-1", "2019-W08-1",
"2019-W09-1", "2019-W10-1", "2019-W11-1", "2019-W12-1", "2019-W13-1",
"2019-W14-1", "2019-W15-1", "2019-W16-1", "2019-W17-1", "2019-W18-1",
"2019-W19-1", "2019-W20-1", "2019-W21-1", "2019-W22-1", "2019-W23-1",
"2019-W24-1", "2019-W25-1", "2019-W26-1", "2019-W27-1", "2019-W28-1",
"2019-W29-1", "2019-W30-1", "2019-W31-1", "2019-W32-1", "2019-W33-1",
"2019-W34-1", "2019-W35-1", "2019-W36-1", "2019-W37-1", "2019-W38-1",
"2019-W39-1", "2019-W40-1", "2019-W41-1", "2019-W42-1", "2019-W43-1",
"2019-W44-1", "2019-W45-1", "2019-W46-1", "2019-W47-1", "2019-W48-1",
"2019-W49-1", "2019-W50-1", "2019-W51-1", "2019-W52-1", "2020-W01-1",
"2020-W02-1", "2020-W03-1", "2020-W04-1", "2020-W05-1", "2020-W06-1",
"2020-W07-1", "2020-W08-1", "2020-W09-1", "2020-W10-1", "2020-W11-1",
"2020-W12-1", "2020-W13-1", "2020-W14-1", "2020-W15-1", "2020-W16-1",
"2020-W17-1", "2020-W18-1", "2020-W19-1", "2020-W20-1", "2020-W21-1",
"2020-W22-1", "2020-W23-1", "2020-W24-1", "2020-W25-1", "2020-W26-1",
"2020-W27-1", "2020-W28-1", "2020-W29-1", "2020-W30-1", "2020-W31-1",
"2020-W32-1", "2020-W33-1", "2020-W34-1", "2020-W35-1", "2020-W36-1",
"2020-W37-1", "2020-W38-1", "2020-W39-1", "2020-W40-1", "2020-W41-1",
"2020-W42-1", "2020-W43-1", "2020-W44-1", "2020-W45-1", "2020-W46-1",
"2020-W47-1", "2020-W48-1", "2020-W49-1", "2020-W50-1", "2020-W51-1",
"2020-W52-1", "2020-W53-1", "2021-W01-1", "2021-W02-1", "2021-W03-1",
"2021-W04-1", "2021-W05-1", "2021-W06-1", "2021-W07-1", "2021-W08-1",
"2021-W09-1", "2021-W10-1", "2021-W11-1", "2021-W12-1", "2021-W13-1",
"2021-W14-1", "2021-W15-1", "2021-W16-1", "2021-W17-1", "2021-W18-1",
"2021-W19-1", "2021-W20-1", "2021-W21-1", "2021-W22-1", "2021-W23-1",
"2021-W24-1", "2021-W25-1", "2021-W26-1", "2021-W27-1", "2021-W28-1",
"2021-W29-1", "2021-W30-1", "2021-W31-1", "2021-W32-1", "2021-W33-1",
"2021-W34-1", "2021-W35-1", "2021-W36-1", "2021-W37-1", "2021-W38-1",
"2021-W39-1", "2021-W40-1", "2021-W41-1", "2021-W42-1", "2021-W43-1"
), date = structure(c(17896, 17903, 17910, 17917, 17924, 17931,
17938, 17945, 17952, 17959, 17966, 17973, 17980, 17987, 17994,
18001, 18008, 18015, 18022, 18029, 18036, 18043, 18050, 18057,
18064, 18071, 18078, 18085, 18092, 18099, 18106, 18113, 18120,
18127, 18134, 18141, 18148, 18155, 18162, 18169, 18176, 18183,
18190, 18197, 18204, 18211, 18218, 18225, 18232, 18239, 18246,
18253, 18260, 18267, 18274, 18281, 18288, 18295, 18302, 18309,
18316, 18323, 18330, 18337, 18344, 18351, 18358, 18365, 18372,
18379, 18386, 18393, 18400, 18407, 18414, 18421, 18428, 18435,
18442, 18449, 18456, 18463, 18470, 18477, 18484, 18491, 18498,
18505, 18512, 18519, 18526, 18533, 18540, 18547, 18554, 18561,
18568, 18575, 18582, 18589, 18596, 18603, 18610, 18617, 18624,
18631, 18638, 18645, 18652, 18659, 18666, 18673, 18680, 18687,
18694, 18701, 18708, 18715, 18722, 18729, 18736, 18743, 18750,
18757, 18764, 18771, 18778, 18785, 18792, 18799, 18806, 18813,
18820, 18827, 18834, 18841, 18848, 18855, 18862, 18869, 18876,
18883, 18890, 18897, 18904, 18911, 18918, 18925), class = "Date")), row.names = c(NA,
148L), class = "data.frame")
# Converting the df to accomodate leap year for weekly observations
Original.df <- Original.df %>%
mutate(
isoweek =stringr::str_replace(YearWeek, "^(\\d{4})(\\d{2})$", "\\1-W\\2-1"),
date = ISOweek::ISOweek2date(isoweek)
)
# creating test and train data
Original.train.df <- Original.df %>%
filter(date >= "2018-12-31", date <= "2021-03-29")
Original.test.df <- Original.df %>%
filter(date >= "2021-04-05", date <= "2021-10-25")
# splitting the original train data to contain only Week, Dependent and Independent variables
Total.train.df<-Original.train.df %>%
mutate(Week.1 = yearweek(ISOweek::ISOweek(date))) %>%
select(-YearWeek, -Production, -date,-isoweek) %>%
as_tsibble(index = Week.1)
#Fitting forecast model(Arima with Fourier terms) to Net.Production.qty
fit_all_models.Prod.1 <- list()
for(K in seq(25)){
fit.Prod.1 <- Total.train.df %>%
model(ARIMA(Net.Production.Qty ~ fourier(K = K),stepwise = FALSE, approximation = FALSE))
names(fit.Prod.1) <- paste0("arima_", K)
fit_all_models.Prod.1 <- bind_cols(fit_all_models.Prod.1, fit.Prod.1)
}
glance(fit_all_models.Prod.1) %>% arrange(AICc) %>% select(.model:BIC)
best_model.Prod.1 <- glance(fit_all_models.Prod.1) %>%
filter(AICc == min(AICc)) %>%
select(.model) %>%
as.character
#Forecasting Net.Production.Qty for 30 steps using the fitted model above-Model.1
Forecast.Net.Prod.1<-fit_all_models.Prod.1 %>%
select(all_of(best_model.Prod.1)) %>%
forecast(h = 30)
#To extract fitted values from the model which has min AICc
fitted.Prod.1<-fit.Prod.1 %>%
filter(AICc == min(AICc)) %>% fitted()
As you see from the last step above I'm trying to extract the fitted values from the model which has minimum AICc- which is not working though
If anyone could help me getting the fitted values from the model above which has min.AICc would be really helpful
Thank you
You are almost there:
# your code .....
# get the fitted based on the selection in best_model.Prod.1
fitted.Prod.1 <- fit_all_models.Prod.1 %>%
select(all_of(best_model.Prod.1)) %>%
fitted()
fitted.Prod.1
# A tsibble: 118 x 3 [1W]
# Key: .model [1]
.model Week.1 .fitted
<chr> <week> <dbl>
1 arima_13 2019 W01 21.0
2 arima_13 2019 W02 486.
3 arima_13 2019 W03 1007.
4 arima_13 2019 W04 965.
5 arima_13 2019 W05 1012.
6 arima_13 2019 W06 1088.
7 arima_13 2019 W07 1175.
8 arima_13 2019 W08 1166.
9 arima_13 2019 W09 1305.
10 arima_13 2019 W10 1613.
# ... with 108 more rows

How do I make a single graph of multiple columns from a dataset?

So I have a large dataset with the daily price of gold in various currencies. The columns in the dataset are Date, USD, GBP, EURO. I want to represent each currency in a single graph. I have this so far:
p1 <- ggplot(data = GOLD) +
geom_line(aes(x = Date, y = USD, GBP, EURO), col ="red") +
labs(title = "Daily price of Gold",
x = "Date", y = "Price in Various Currencies")
But, having y represent each of the currencies is erroring out.
If this is the structure of your data frame, called gold:
str(gold)
'data.frame': 602 obs. of 5 variables:
$ Date: Date, format: "1969-12-31" "1970-01-30" "1970-02-27" "1970-03-31" ...
$ USD : num 35.2 35 35 35.3 35.9 ...
$ EUR : num 22.2 23.2 23.3 23.4 23.8 ...
$ GBP : num 14.7 14.5 14.6 14.7 14.9 ...
$ JPY : num 12592 12496 12530 12628 12858 ...
Then the following commands will produce the desired graph:
library(tidyr) # Needed to reshape the data to longer format
library(ggplot2) # Needed to plot the data
library(scales) # Needed to modify the y-axis tick labels
gold %>%
pivot_longer(cols=USD:JPY, names_to="Currency", values_to="Price") %>%
ggplot(aes(x = Date, y = Price, color=Currency)) +
geom_line() +
labs(title = "Daily price of gold",
x = "Date", y = "Price in various currencies") +
scale_y_log10(labels=comma) # Otherwise you get scientific notation
Data: (available from https://www.gold.org/goldhub/data/gold-prices)
gold <- structure(list(Date = structure(c(-1, 29, 57, 89, 119, 148, 180,
211, 242, 272, 302, 333, 364, 393, 421, 454, 484, 515, 545, 575,
607, 637, 666, 698, 729, 760, 789, 820, 848, 881, 911, 942, 973,
1002, 1034, 1064, 1093, 1126, 1154, 1184, 1215, 1246, 1275, 1307,
1338, 1366, 1399, 1429, 1460, 1491, 1519, 1548, 1580, 1611, 1639,
1672, 1702, 1733, 1764, 1793, 1825, 1856, 1884, 1915, 1945, 1975,
2006, 2037, 2066, 2098, 2129, 2157, 2190, 2220, 2248, 2281, 2311,
2342, 2372, 2402, 2434, 2464, 2493, 2525, 2556, 2587, 2615, 2646,
2675, 2707, 2737, 2766, 2799, 2829, 2860, 2890, 2920, 2952, 2980,
3011, 3039, 3072, 3102, 3133, 3164, 3193, 3225, 3255, 3284, 3317,
3345, 3375, 3406, 3437, 3466, 3498, 3529, 3557, 3590, 3620, 3651,
3682, 3711, 3742, 3772, 3802, 3833, 3864, 3893, 3925, 3956, 3984,
4017, 4047, 4075, 4107, 4137, 4166, 4198, 4229, 4260, 4290, 4320,
4351, 4382, 4411, 4439, 4472, 4502, 4533, 4563, 4593, 4625, 4655,
4684, 4716, 4747, 4778, 4806, 4837, 4866, 4898, 4928, 4957, 4990,
5020, 5051, 5081, 5111, 5143, 5172, 5202, 5233, 5264, 5293, 5325,
5356, 5384, 5417, 5447, 5478, 5509, 5537, 5566, 5598, 5629, 5657,
5690, 5720, 5751, 5782, 5811, 5843, 5874, 5902, 5933, 5963, 5993,
6024, 6055, 6084, 6116, 6147, 6175, 6208, 6238, 6266, 6298, 6328,
6357, 6389, 6420, 6451, 6481, 6511, 6542, 6573, 6602, 6633, 6664,
6693, 6725, 6755, 6784, 6817, 6847, 6878, 6908, 6938, 6970, 6998,
7029, 7057, 7090, 7120, 7151, 7182, 7211, 7243, 7273, 7302, 7335,
7363, 7393, 7424, 7455, 7484, 7516, 7547, 7575, 7608, 7638, 7669,
7700, 7728, 7757, 7789, 7820, 7848, 7881, 7911, 7942, 7973, 8002,
8034, 8065, 8093, 8125, 8155, 8184, 8216, 8247, 8278, 8308, 8338,
8369, 8400, 8429, 8457, 8490, 8520, 8551, 8581, 8611, 8643, 8673,
8702, 8734, 8765, 8796, 8824, 8855, 8884, 8916, 8946, 8975, 9008,
9038, 9069, 9099, 9129, 9161, 9189, 9220, 9248, 9281, 9311, 9342,
9373, 9402, 9434, 9464, 9493, 9526, 9555, 9584, 9616, 9647, 9675,
9708, 9738, 9769, 9800, 9829, 9861, 9892, 9920, 9951, 9981, 10011,
10042, 10073, 10102, 10134, 10165, 10193, 10226, 10256, 10284,
10316, 10346, 10375, 10407, 10438, 10469, 10499, 10529, 10560,
10591, 10620, 10648, 10681, 10711, 10742, 10772, 10802, 10834,
10864, 10893, 10925, 10956, 10987, 11016, 11047, 11075, 11108,
11138, 11169, 11200, 11229, 11261, 11291, 11320, 11353, 11381,
11411, 11442, 11473, 11502, 11534, 11565, 11593, 11626, 11656,
11687, 11718, 11746, 11775, 11807, 11838, 11866, 11899, 11929,
11960, 11991, 12020, 12052, 12083, 12111, 12142, 12172, 12202,
12233, 12264, 12293, 12325, 12356, 12384, 12417, 12447, 12475,
12508, 12538, 12569, 12599, 12629, 12661, 12691, 12720, 12752,
12783, 12814, 12842, 12873, 12902, 12934, 12964, 12993, 13026,
13056, 13087, 13117, 13147, 13179, 13207, 13238, 13266, 13299,
13329, 13360, 13391, 13420, 13452, 13482, 13511, 13544, 13572,
13602, 13633, 13664, 13693, 13725, 13756, 13784, 13817, 13847,
13878, 13909, 13938, 13969, 13999, 14029, 14060, 14091, 14120,
14152, 14183, 14211, 14244, 14274, 14302, 14334, 14364, 14393,
14425, 14456, 14487, 14517, 14547, 14578, 14609, 14638, 14666,
14699, 14729, 14760, 14790, 14820, 14852, 14882, 14911, 14943,
14974, 15005, 15033, 15064, 15093, 15125, 15155, 15184, 15217,
15247, 15278, 15308, 15338, 15370, 15399, 15429, 15460, 15491,
15520, 15552, 15583, 15611, 15644, 15674, 15705, 15736, 15764,
15793, 15825, 15856, 15884, 15917, 15947, 15978, 16009, 16038,
16070, 16101, 16129, 16160, 16190, 16220, 16251, 16282, 16311,
16343, 16374, 16402, 16435, 16465, 16493, 16525, 16555, 16584,
16616, 16647, 16678, 16708, 16738, 16769, 16800, 16829, 16860,
16891, 16920, 16952, 16982, 17011, 17044, 17074, 17105, 17135,
17165, 17197, 17225, 17256, 17284, 17317, 17347, 17378, 17409,
17438, 17470, 17500, 17529, 17562, 17590, 17620, 17651, 17682,
17711, 17743, 17774, 17802, 17835, 17865, 17896, 17927, 17955,
17984, 18016, 18047, 18075, 18108, 18138, 18169, 18200, 18229,
18261, 18292), class = "Date"), USD = c(35.2, 34.99, 35.02, 35.3,
35.85, 35.45, 35.49, 35.3, 35.8, 36.4, 37.25, 37.54, 37.38, 38.05,
38.8, 38.88, 39.7, 40.84, 40.1, 42.4, 40.65, 42.6, 42.34, 43.6,
43.55, 47.15, 48.2, 48.38, 49.6, 59.45, 64.65, 68.3, 66.88, 64.2,
64.39, 63.6, 64.9, 66, 85, 90, 90.72, 114.75, 123.25, 115.6,
103.5, 100, 98, 101, 112.25, 132.5, 162.5, 173, 169.25, 156.75,
144.25, 156, 156, 151.25, 167, 184, 186.5, 175.8, 181.75, 177.25,
167, 167, 166.25, 166.7, 159.8, 141.25, 142.9, 138.15, 140.25,
128.15, 132.3, 129.6, 128.4, 125.5, 123.8, 112.5, 104, 116, 123.15,
130.25, 134.5, 132.3, 142.75, 148.9, 147.25, 142.95, 143, 144.1,
146, 154.05, 161.5, 160.05, 164.95, 175.75, 182.25, 181.6, 170.85,
184.15, 183.05, 200.25, 208.7, 217.1, 242.6, 193.4, 226, 233.7,
251.3, 240.1, 245.3, 274.6, 277.5, 296.45, 315.1, 397.25, 382,
415.65, 512, 653, 637, 494.5, 518, 535.5, 653.5, 614.25, 631.25,
666.75, 629, 619.75, 589.75, 506.5, 489, 513.75, 482.75, 479.25,
426, 406, 425, 428.75, 427, 414.5, 397.5, 387, 362.6, 320, 361.25,
325.25, 317.5, 342.9, 411.5, 397, 423.25, 436, 456.9, 499.5,
408.5, 414.75, 429.25, 437.5, 416, 422, 414.25, 405, 382, 405,
382.4, 373.75, 394.25, 388.5, 375.8, 384.25, 373.05, 342.35,
348.25, 343.75, 333.5, 329, 308.3, 306.65, 287.75, 329.25, 321.35,
314, 317.75, 327.5, 333.25, 325.75, 325.1, 325.3, 326.8, 350.5,
338.15, 344, 345.75, 343.2, 346.75, 357.5, 384.7, 423.2, 401,
389.5, 388.75, 400.5, 405.85, 421, 453.25, 451, 447.3, 462.5,
453.4, 459.5, 468.8, 492.5, 484.1, 458, 426.15, 456.95, 449,
455.5, 436.55, 436.8, 427.75, 396.7, 412.4, 422.6, 410.25, 394,
387, 383.2, 377.55, 361.8, 373, 368.3, 359.8, 366.5, 375.3, 408.15,
398.6, 415.05, 407.7, 368.5, 367.75, 363.05, 352.2, 372.3, 387.75,
408.4, 379.5, 384.85, 386.2, 366, 362.7, 355.65, 357.75, 360.4,
368.35, 362.85, 347.4, 354.9, 357.45, 366.3, 353.15, 354.1, 353.1,
341.7, 336.35, 337.5, 343.4, 357.85, 340, 349, 339.25, 334.2,
332.9, 330.45, 327.6, 337.8, 354.3, 377.45, 378.45, 401.75, 371.55,
355.5, 369.6, 370.9, 391.75, 377.9, 381.55, 389.2, 376.45, 387.6,
388.25, 384, 385.75, 394.85, 383.85, 383.1, 383.25, 374.9, 376.4,
392, 389.75, 384.3, 387.05, 383.35, 382.35, 384, 382.65, 387.8,
387, 405.55, 400.65, 396.35, 391.3, 390.55, 382, 385.3, 386.45,
379, 379.5, 371.3, 369.25, 345.5, 358.6, 348.15, 340.15, 345.6,
334.55, 326.35, 325.35, 332.1, 311.4, 296.8, 290.2, 304.85, 297.4,
301, 310.7, 293.6, 296.3, 288.85, 273.4, 293.85, 292.3, 294.7,
287.8, 285.4, 287.05, 279.45, 286.6, 268.6, 261, 255.6, 254.8,
299, 299.1, 291.35, 290.25, 283.3, 293.65, 276.75, 275.05, 272.25,
288.15, 276.75, 277, 273.65, 264.5, 269.1, 274.45, 264.5, 266.7,
257.7, 263.15, 267.5, 270.6, 265.9, 273, 293.1, 278.75, 275.5,
276.5, 282.3, 296.85, 301.4, 308.2, 326.6, 318.5, 304.65, 312.8,
323.7, 316.9, 319.05, 347.2, 367.5, 347.45, 334.85, 336.75, 361.4,
346, 354.75, 375.6, 388, 386.25, 398.35, 416.25, 399.75, 395.85,
423.7, 388.5, 393.25, 395.8, 391.4, 407.25, 415.65, 425.55, 453.4,
435.6, 422.15, 435.45, 427.5, 435.7, 414.45, 437.1, 429, 433.25,
473.25, 470.75, 495.65, 513, 568.75, 556, 582, 644, 653, 613.5,
632.5, 623.5, 599.25, 603.75, 646.7, 632, 650.5, 664.2, 661.75,
677, 659.1, 650.5, 665.5, 672, 743, 789.5, 783.5, 833.75, 923.25,
971.5, 933.5, 871, 885.75, 930.25, 918, 833, 884.5, 730.75, 814.5,
869.75, 919.5, 952, 916.5, 883.25, 975.5, 934.5, 939, 955.5,
995.75, 1040, 1175.75, 1087.5, 1078.5, 1108.25, 1115.5, 1179.25,
1207.5, 1244, 1169, 1246, 1307, 1346.75, 1383.5, 1405.5, 1327,
1411, 1439, 1535.5, 1536.5, 1505.5, 1628.5, 1813.5, 1620, 1722,
1746, 1531, 1744, 1770, 1662.5, 1651.25, 1558, 1598.5, 1622,
1648.5, 1776, 1719, 1726, 1657.5, 1664.75, 1588.5, 1598.25, 1469,
1394.5, 1192, 1314.5, 1394.75, 1326.5, 1324, 1253, 1204.5, 1251,
1326.5, 1291.75, 1288.5, 1250.5, 1315, 1285.25, 1285.75, 1216.5,
1164.25, 1182.75, 1206, 1260.25, 1214, 1187, 1180.25, 1191.4,
1171, 1098.4, 1135, 1114, 1142.35, 1061.9, 1060, 1111.8, 1234.9,
1237, 1285.65, 1212.1, 1320.75, 1342, 1309.25, 1322.5, 1272,
1178.1, 1145.9, 1212.8, 1255.6, 1244.85, 1266.45, 1266.2, 1242.25,
1267.55, 1311.75, 1283.1, 1270.15, 1280.2, 1291, 1345.05, 1317.85,
1323.85, 1313.2, 1305.35, 1250.45, 1220.95, 1202.45, 1187.25,
1214.95, 1217.55, 1279, 1323.25, 1319.15, 1295.4, 1282.3, 1295.55,
1409, 1427.55, 1528.4, 1485.3, 1510.95, 1460.15, 1514.75, 1584.2
), EUR = c(22.24, 23.2, 23.26, 23.42, 23.79, 23.54, 23.55, 23.45,
23.58, 23.98, 24.58, 24.71, 24.41, 25.09, 25.58, 25.61, 26.14,
26.9, 26.39, 27.92, 26.1, 27.39, 27.22, 27.93, 27.06, 28.99,
29.51, 29.36, 30.17, 36.01, 39.03, 41.31, 40.23, 38.78, 39.27,
38.71, 39.55, 40.81, 48.14, 51.83, 52.61, 65.04, 67.54, 63.58,
57.35, 54.93, 54.3, 58.89, 65.95, 82.65, 100.08, 100.68, 97.53,
92.29, 85.08, 91.61, 93.61, 90.4, 99.31, 107.71, 106.18, 98.8,
99.58, 98.85, 92.69, 91.82, 92.63, 98.41, 94.56, 85.78, 84.59,
83.49, 84.68, 80.12, 84.37, 85.94, 87.07, 84.52, 83.13, 75.95,
70.12, 78.1, 83.06, 87.92, 90.21, 89.95, 97.08, 102.08, 100.64,
97.73, 97.61, 100.32, 102.04, 107.8, 111.51, 110.18, 110.08,
117.4, 119.82, 118.79, 113.18, 122.76, 120.43, 129.16, 132.48,
135.68, 141.49, 122.4, 137.06, 144.84, 154.64, 148.04, 152.76,
172, 169.03, 179.68, 190.38, 233.23, 231.45, 244.87, 299.12,
385.01, 381.48, 321.56, 317.27, 323.09, 392.72, 372.37, 386.52,
412.83, 404.91, 406.73, 392.41, 363.31, 357.95, 375.1, 369.74,
386.14, 353.4, 346.87, 362.53, 349.87, 347.03, 332.94, 327.48,
327.92, 308.91, 285.71, 318.81, 284.76, 301.04, 315.16, 388.34,
383.37, 416.77, 423.24, 429.9, 486.07, 394.41, 410.93, 430.88,
447.29, 431.65, 456.53, 452.93, 440.9, 416.46, 451.49, 432, 436.19,
428.55, 421.4, 425.18, 437.24, 431.92, 412.65, 419.37, 436.4,
421.37, 423.66, 402.45, 402.82, 400.46, 425.73, 417.93, 403.43,
404.96, 393.64, 399.98, 375.93, 366.57, 353.9, 347.51, 364.1,
328.64, 348.01, 329.63, 350.96, 336.16, 332.15, 349.46, 383.64,
369.82, 345.5, 337.8, 334.76, 338.02, 346.74, 371.84, 375.9,
373.31, 391.91, 374.28, 384.69, 372.16, 371.97, 351.76, 352.89,
330.48, 347.7, 345.58, 360.76, 364.4, 374.62, 369.07, 341.8,
337.87, 336.58, 332.66, 335.74, 321.64, 329.38, 321.84, 324.56,
330.9, 310.91, 318.07, 312.36, 315.19, 332.89, 310.67, 321.26,
316.15, 283.87, 280.65, 280.21, 265.93, 267.8, 278.03, 291.86,
262.61, 264.8, 265.67, 251.05, 256.11, 279.75, 282.52, 288.89,
308.46, 292.89, 280.79, 273.61, 276.67, 277.92, 250.28, 264.7,
268.95, 261.69, 257.99, 251.28, 243.14, 246.81, 224.5, 241.25,
254.97, 261.39, 266.67, 264.28, 270.45, 274.97, 281.13, 300.65,
321.12, 354.79, 318.97, 298.71, 318.85, 327.89, 348.19, 335.18,
332.98, 331.04, 317.52, 325.31, 317.59, 313.37, 313, 314.77,
298.37, 311.1, 308.79, 297.3, 293.58, 291.35, 291.51, 289.94,
287.07, 280.74, 294.95, 288.98, 285.63, 294.55, 290.67, 314.78,
306.5, 304.48, 308.65, 307.01, 298.59, 293.51, 294.9, 296.14,
294.25, 291.75, 290.49, 288.68, 310.07, 297.45, 300.81, 301.56,
296.89, 305.23, 298.45, 298.75, 273.02, 266.62, 266.06, 284.48,
275.71, 284.19, 284.81, 267.29, 272.95, 262.35, 246.34, 251.03,
247.54, 254.8, 245.08, 251.3, 261.48, 258.85, 270.89, 257.55,
253.08, 238.81, 241.22, 280.75, 284.56, 289.35, 289.56, 289.55,
305, 289.22, 301.82, 293.56, 300.59, 298.67, 311.55, 310.08,
312.06, 309.13, 292.31, 284.41, 290.02, 291.52, 296.81, 315.6,
319.63, 303.89, 300.53, 321.84, 309.48, 307.68, 310.53, 327.91,
343.18, 345.48, 342.03, 349.57, 322.5, 310.74, 318.96, 327.53,
320, 320.72, 330.86, 342.34, 322.37, 306.86, 301.75, 307.27,
301.3, 315.18, 342.11, 333.18, 332.26, 332.32, 330, 321.78, 318.59,
344.78, 324.09, 322.03, 325.32, 325.1, 335.1, 334.66, 334.54,
341.15, 320.47, 323.85, 328.06, 328.93, 337.5, 335.65, 361.05,
353.19, 352.28, 392.53, 393.03, 420.42, 434.91, 468.38, 466.35,
480.93, 511.25, 508.39, 479.8, 495.63, 487.09, 473.06, 473.03,
487.87, 479.28, 500.6, 502.82, 497.13, 496.06, 489.8, 481.66,
486.17, 492.94, 522.45, 545.71, 533.77, 570.26, 623.56, 639.94,
589.13, 559.45, 569.96, 590.43, 588.37, 565.8, 629.69, 576.28,
641.89, 625.7, 717.52, 749.58, 690.29, 666.55, 689.18, 666.24,
662.32, 665.83, 681.23, 704.87, 783.13, 757.97, 775.93, 812.08,
824.4, 886.89, 984.07, 1015.59, 897.3, 980.37, 957.37, 968.96,
1062.8, 1047.67, 967.91, 1021.58, 1014.02, 1034.98, 1068.8, 1038.38,
1133.26, 1259.55, 1207.42, 1234.59, 1297.03, 1179.37, 1332.26,
1323.17, 1248.4, 1247.59, 1260.06, 1259.6, 1317.04, 1307.81,
1380.49, 1326.59, 1327.08, 1257.21, 1226.43, 1215.05, 1244.65,
1114.23, 1076, 917.03, 989.95, 1057.75, 979.94, 973.89, 920.28,
874.12, 927.66, 960.43, 937.24, 929.28, 916.42, 960.45, 960.58,
976.12, 962.99, 929.24, 948.74, 996.65, 1116.8, 1082.33, 1105.21,
1053.28, 1086.7, 1050.98, 994.16, 1012.94, 997.99, 1034.13, 1005.44,
975.79, 1027.49, 1136.53, 1085.52, 1122.5, 1088.79, 1188.85,
1200.09, 1175.53, 1176.81, 1160.37, 1110.58, 1086.42, 1122.24,
1181.63, 1163.9, 1163, 1126.01, 1089.17, 1075.11, 1103.33, 1085.35,
1090.3, 1073.68, 1075.12, 1079.71, 1080.52, 1076.43, 1086.91,
1118.26, 1071, 1043.5, 1033.48, 1022.17, 1072.28, 1075.34, 1118.84,
1153.21, 1158.47, 1153.67, 1144.2, 1162.61, 1237.27, 1282.15,
1387.88, 1362.41, 1354.32, 1324.28, 1349.44, 1429.53), GBP = c(14.66,
14.54, 14.55, 14.67, 14.93, 14.8, 14.85, 14.81, 14.99, 15.23,
15.6, 15.69, 15.46, 15.75, 16.06, 16.08, 16.41, 16.89, 16.57,
17.53, 16.53, 17.15, 17, 17.48, 17.06, 18.18, 18.49, 18.5, 19,
22.75, 26.45, 27.88, 27.32, 26.53, 27.55, 27.04, 27.66, 27.73,
34.25, 36.3, 36.45, 44.73, 47.76, 46.23, 42.09, 41.43, 40.18,
43.07, 48.32, 58.06, 70.54, 72.23, 69.56, 65.41, 60.44, 65.55,
67.31, 64.84, 71.54, 79.11, 79.36, 73.88, 74.81, 73.84, 70.91,
72.26, 76.49, 77.62, 75.72, 69.15, 68.78, 68.48, 69.32, 63.13,
65.32, 67.61, 69.76, 71.37, 69.36, 63.01, 58.51, 69.84, 77.65,
78.82, 79.04, 77.14, 83.29, 86.57, 85.64, 83.16, 83.14, 82.96,
83.77, 88.15, 87.75, 88.08, 86.05, 90.13, 93.87, 97.32, 93.39,
100.46, 98.41, 103.68, 107.38, 109.84, 116.92, 99.46, 110.7,
117.44, 124.19, 116.22, 118.82, 132.69, 127.29, 131.87, 139.89,
180.36, 184.01, 188.97, 230.63, 288.11, 280.25, 228.51, 229.36,
228.36, 277.32, 262.16, 263.41, 279.27, 258.16, 262.83, 246.65,
213.98, 221.77, 228.89, 225.53, 231.52, 220.67, 220.47, 229.85,
237.53, 229.57, 212.02, 208.22, 205.74, 199.07, 179.57, 201.37,
181.65, 182.1, 197.3, 239.66, 234.29, 252.39, 268.56, 282.47,
328.62, 269.64, 279.58, 275.07, 272.67, 271.9, 277.5, 277.28,
270.54, 255.43, 276.26, 263.45, 266.68, 264.51, 269.32, 268.72,
277.34, 275.01, 261.84, 266.14, 278.34, 273.14, 274.62, 266.01,
271.13, 266.44, 266.06, 258.63, 244.07, 242.56, 232.52, 239.23,
231.19, 225.61, 218.54, 226.08, 248.05, 233.69, 231.81, 222.92,
233.07, 226.26, 239.53, 258.45, 292.47, 285.31, 271.71, 262.23,
264.62, 262.52, 262.31, 272.96, 276.69, 277.22, 290.52, 277.56,
282.68, 272.24, 269.72, 257.71, 258.76, 240.29, 242.03, 238.89,
247.76, 255.59, 255.36, 254.01, 234.59, 233.19, 228.37, 226.78,
225.08, 221.84, 227.01, 223.53, 230.08, 240.8, 221, 228.66, 226.94,
237.83, 260.13, 247.19, 247.05, 241.24, 223.67, 224.31, 216.49,
201.89, 200.16, 204.89, 217.99, 195.22, 198.43, 200.1, 186.26,
189.85, 204.51, 207.51, 212.12, 227.52, 215.34, 206.66, 202.45,
205.14, 207.54, 188.75, 197.82, 200.97, 196.89, 189.55, 184.53,
180.36, 186.38, 171.54, 195.9, 217.12, 220.81, 219.88, 222.23,
230.22, 224.38, 225.81, 241.8, 253.4, 270.54, 249.78, 237.71,
248.64, 249.85, 264.79, 252.13, 256.75, 262.17, 248.27, 256.39,
251.55, 249.91, 251.06, 250.38, 235.41, 244.77, 244.97, 236.16,
238.19, 240.67, 242.19, 241.92, 243.29, 239.58, 246.83, 242.62,
242.51, 253.55, 249.27, 268.4, 261.71, 259.65, 260.77, 252.07,
245.86, 247.45, 247.25, 242.42, 233.05, 220.97, 215.77, 215.6,
219.8, 212.03, 209.63, 211.25, 201.02, 199.3, 200.61, 205.58,
185.7, 176.16, 176.38, 186.45, 180.63, 179.75, 185.83, 180.05,
177.58, 176.56, 163.27, 172.91, 174.54, 178.54, 172.98, 173.73,
179.18, 173.11, 178.01, 167.53, 165.58, 157.78, 158.46, 181.56,
182.28, 182.93, 180.09, 174.78, 186.01, 173.48, 175.78, 182.14,
190.34, 184.79, 190.38, 185.09, 182.16, 189.83, 183.73, 181.03,
184.92, 181.27, 183.92, 188.3, 192.41, 186.58, 188.22, 199.43,
191.67, 193.19, 189.98, 199.75, 209.88, 211.66, 211.49, 223.22,
208.96, 195.02, 202.21, 205.84, 202.56, 205.04, 215.67, 223.58,
220.59, 211.84, 210.7, 220.59, 209.68, 220.69, 237.46, 233.54,
227.61, 231.62, 232.52, 219.61, 213.3, 230.54, 219.08, 214.49,
218.25, 215.24, 226.38, 229.7, 232.25, 237.2, 226.89, 223.82,
226.13, 226.24, 228.13, 227.4, 243.86, 243.67, 240.89, 267.51,
265.92, 286.44, 298.82, 320, 317.49, 335.53, 354.3, 348.96, 331.7,
338.77, 327.79, 320.81, 316.56, 328.77, 322.92, 332.33, 338.92,
337.4, 338.53, 333.2, 324.22, 327.5, 333.16, 364.69, 380.05,
381.05, 418.84, 464.41, 488.39, 469.69, 439.78, 448.21, 467.43,
463.43, 456.7, 496.23, 452.27, 530.81, 604.94, 637.79, 667.91,
639.41, 596.07, 604.94, 567.45, 566.4, 586.27, 622.6, 630.93,
716.44, 673.44, 673.05, 727.96, 735.38, 770.42, 831.07, 831.5,
746.44, 810.72, 829.42, 842.35, 888.37, 897.71, 828.47, 867.51,
897.72, 920.59, 933.5, 937.74, 992.08, 1113.77, 1039.93, 1066.85,
1110.12, 985.14, 1105.16, 1108.02, 1040.53, 1016.87, 1012.25,
1019.16, 1035.23, 1037.87, 1099.83, 1067.01, 1076.97, 1019.69,
1050.02, 1046.48, 1052.55, 943.85, 919.79, 785.92, 867.06, 901.64,
819.13, 824.1, 764.93, 727.25, 761.2, 791.54, 774.83, 763.08,
745.52, 769.07, 761.27, 774.2, 750.39, 727.72, 755.24, 773.45,
839.1, 785.56, 799.6, 768.02, 780.76, 744.58, 703.88, 737.97,
735.44, 739.67, 705.44, 719.18, 783.79, 886.12, 860.64, 877.64,
832.77, 987.99, 1010.77, 999.66, 1018.09, 1041.85, 942.93, 927.37,
963.99, 1009, 995.52, 978.9, 980.83, 956.35, 961.47, 1018.01,
956.36, 956.47, 945.74, 954.35, 945.85, 956.45, 943.72, 953.43,
980.99, 947.13, 930.78, 925.14, 910.43, 950.85, 954.27, 1004.24,
1005.93, 991.77, 994.13, 983.62, 1027.89, 1107.1, 1165.87, 1255,
1205.31, 1167.66, 1128.84, 1143.42, 1201.79), JPY = c(12592.44,
12496.35, 12529.95, 12627.65, 12858.36, 12757.88, 12764.72, 12728.16,
12799.92, 13018.66, 13341.25, 13403.93, 13239.03, 13613.21, 13867.1,
13892.95, 14188.38, 14594.98, 14328.74, 15153.74, 13538.98, 14059.41,
13957.5, 14250.08, 13691.48, 14624.17, 14619.8, 14695.64, 15092.19,
18096.15, 19085.52, 20559.69, 20090.92, 19326.34, 19410.68, 19127.31,
19568.2, 19897.07, 22585.63, 23834.22, 24145.47, 30392.78, 32263.28,
30535.41, 27419.59, 26534.94, 26098.24, 28232.64, 31384.58, 39453.89,
46802.46, 47602.1, 47234.18, 44183.03, 41041.61, 46668.94, 47254.41,
45131.84, 50150.83, 55215.86, 56029.4, 52492.53, 52067.51, 51834.86,
48788.12, 48777.59, 49565.26, 49794.25, 47625.81, 42800.94, 43162.37,
41975.69, 42788.35, 38950.05, 40006.82, 38873.24, 38474.65, 37717.84,
36897.27, 33015.97, 30015.22, 33347.41, 36300.55, 38700.65, 39440.3,
38185.75, 40377.01, 41380.39, 40936.12, 39666.76, 38285.79, 38493.04,
39036.11, 40680.98, 40276.31, 39109.66, 39538.1, 42495.47, 43462.15,
40096.07, 38241.67, 40838.54, 37298.9, 37789.89, 39731.94, 41080.4,
43492.65, 38590.52, 43893.74, 47327.21, 50918.25, 50379.21, 54567.22,
60506.23, 60400.85, 64222.08, 69384.93, 89144.59, 90807.88, 103747.21,
122753.24, 156299.39, 160301.01, 123625.03, 123852.21, 119317.25,
143581.44, 139733.44, 138287.63, 140611.01, 132821.9, 134174.05,
119873.91, 104745.2, 102568.08, 108495.29, 104139.22, 107310.34,
96652.77, 97559.14, 97458.09, 99645.86, 99518.62, 88783.57, 87350.12,
88366.05, 85797.72, 79371.51, 85177.74, 79200.8, 80809.09, 88289.82,
107608.45, 106483.75, 117233.06, 109033.58, 107339.81, 119945.76,
97069.41, 99109.49, 102120.63, 104637.36, 99037.93, 102048.79,
102037.58, 95501.08, 89401.56, 94067.22, 88651.45, 87803.93,
92049.07, 87261.11, 85317.53, 89025.08, 88552.94, 83983.73, 84168.28,
84476.24, 81941.05, 81426.13, 77540.56, 78085.95, 74735.07, 82478.9,
80887.16, 78835.6, 78952.48, 77544.39, 79544.62, 70455.94, 68753.77,
65726.53, 65450.46, 67594.74, 60993.19, 61718.4, 57680.74, 59899.76,
56735.83, 54972.42, 59443.07, 65322.55, 65478.19, 63105.32, 61492.07,
61523.85, 62150.7, 61445.03, 63736.17, 64952.37, 65632.63, 69287.93,
64394.79, 67278.39, 64725.48, 65203.72, 58756.86, 58543.8, 54725.53,
56695.21, 56080.25, 56984.01, 58274.86, 58095.28, 58358.48, 53135.74,
51768.65, 51497.63, 51252.96, 51430.46, 49082.16, 50737.68, 50127.67,
51480.31, 53698.52, 50443.76, 52020.64, 51173.85, 53571.85, 58335.06,
57287.2, 59972.28, 60672.52, 57987.09, 58375.7, 55420.9, 53602.28,
54393.81, 55780.68, 56458.81, 49292.09, 51243.87, 52377.16, 48101.57,
48220.78, 50208.24, 48765.23, 49902.39, 50793.19, 49851.52, 47532.41,
47120.95, 46668.54, 47629.39, 44120.18, 44460.3, 45619.62, 45481.28,
44875.08, 43087.08, 43240.65, 45569.99, 41899.63, 41874.13, 41795.6,
41568.03, 41557.52, 41222.92, 38676.62, 38817.25, 39404.32, 40441.07,
40416.99, 42136.42, 38903.5, 37736.97, 40092.83, 40475.44, 43721.26,
41192.97, 39738.41, 39990.29, 38204.02, 40564.26, 38298.92, 38467.2,
38642.5, 39078.28, 37214.24, 37907.73, 38236.85, 37096.34, 36397.87,
33868.79, 32746.79, 32529.05, 32860.52, 33750.11, 37451.17, 37881.59,
39124.04, 39373.31, 39920.98, 43359.35, 42136.35, 42330.2, 40990.61,
42218.43, 41899.67, 41121.12, 41968.46, 42211.13, 43164.33, 42253.91,
42858.84, 41943.7, 43279.41, 43104.44, 43168.42, 40272.75, 38282.53,
38639.82, 39136.33, 40094.41, 37452.06, 37879.08, 37733.25, 38654.96,
37570.53, 40139.85, 41052.78, 40682.66, 41121.96, 41704.14, 38601.33,
39998.84, 34061.7, 36224.52, 32463.81, 33186.3, 34058.46, 33095.26,
34209.99, 32714.12, 31591.44, 29333.93, 27937.54, 31834.53, 31214.06,
29771.58, 29708.54, 30325.83, 32258.91, 28384.86, 29726.01, 29314.52,
30487.7, 30326.26, 29539.28, 29570.61, 28880.75, 29809.53, 31342.18,
30757.38, 31282.57, 32294.96, 32508.22, 31784.35, 33749.21, 33206.91,
32488.36, 34916.98, 34120.39, 33919.56, 36238.09, 37764.65, 39725.93,
39946.03, 39572.87, 40532.67, 38175.41, 36484.87, 37087.1, 39407.23,
38823.41, 39088.39, 41202.22, 44077.95, 41077.27, 39706.49, 40160.8,
43225.23, 41545.95, 42763.34, 43824.99, 43345.42, 42462.39, 43627.27,
44609.51, 42313.53, 43250.55, 44079.62, 42872.92, 43463.95, 43187.69,
43623.47, 44693.65, 45810.85, 45189.13, 46607.24, 44635.91, 43673.51,
45410.89, 45725.4, 45711.46, 44667.34, 48435.03, 48088.75, 48149.24,
53638.15, 54797.65, 59306.99, 60549.39, 66580.71, 64398.7, 68670.17,
73544.8, 73207.82, 70132.24, 72380.14, 73127.19, 70750.44, 70732.33,
74794.08, 75305.96, 78684.47, 78697.72, 78136.13, 80904.88, 80288.24,
80333.49, 79237.75, 77894.88, 85456.14, 91017.5, 86909.73, 93142.38,
98164.55, 101138, 92915.91, 91028.21, 93504.19, 98611.14, 99222.02,
90401.32, 93902.94, 71869.26, 77577.05, 78842.83, 82580.29, 93148.43,
90522.69, 86898.55, 93116.34, 90165.22, 89388.1, 88636.96, 89154.46,
94140.79, 101284.97, 101240.8, 97771.42, 98484.63, 104232.31,
110861.29, 109924.75, 110081.55, 101305.53, 104626.6, 109186.77,
108480.7, 115895.78, 113993.07, 108721.1, 115603.22, 119264.31,
124590.47, 124825.25, 121584.17, 125703.89, 138678.32, 124869.58,
134272.93, 135541.96, 117795.12, 132980, 143263.78, 136815.43,
131844.03, 122170.56, 127544.3, 126678.19, 129077.53, 138172.78,
137399.66, 142343.2, 143315.73, 151925.08, 146555, 150267.45,
143095.27, 140809.62, 118407.31, 129287.64, 136845.88, 130162.81,
129897.62, 128263.33, 126598.97, 127583.22, 135389.21, 133030.85,
131620.27, 127232.12, 133216.07, 132168.67, 133570.13, 133443.96,
130518.24, 140374.68, 144593.36, 148035.26, 145127.63, 142350.96,
141240.52, 147846.75, 143289.4, 136086.24, 137544.97, 133418.21,
137853.05, 130911.02, 127512.7, 134600.03, 139389.33, 139032.6,
137558.11, 134427.93, 135495.74, 137534.85, 135422.27, 133922.96,
133668.11, 134238.58, 133652.03, 136530.93, 140482.78, 138713.61,
141171.16, 140022.71, 139579.19, 140057.91, 144371.2, 144432.12,
144327.12, 143260.77, 145431.14, 146818.91, 140621.15, 140791.42,
143696.89, 141819.72, 138506.09, 136673.12, 133333.66, 134853.78,
137113.17, 138252.77, 140325.48, 144009.28, 146847.76, 143381.34,
142816.14, 140664.32, 151805.65, 154996.22, 162231.99, 160523.77,
163341.24, 159901.01, 164615.44, 171703.5)), row.names = c(NA,
-602L), class = "data.frame")

Yearly seasonal sums for DJF

I want to create sums for the meteorological nomenclature of DJF, that means December values are from the year x-1.
There is already a suggestion, using the packages seas and zoo for my kind of problem: Link to the reference. Can I use a loop regarding the time index of my zoo-object, to get the winter sums for each year and different columns? There are already only the winter months in my sample data:
structure(c(0.335767631885527, 0.329964137686826, 0.324867678295622,
0.346234032749876, 0.315486588076342, 0.373440783616547, 0.393108355980974,
0.310526442402042, 0.955068399718777, 0.959654624426492, 0.293930575800507,
0.350949140946517, 0.657761387039141, 0.53822087533681, 0.296938223280703,
0.318325593619261, 0.827528522109129, 0.914084376992577, 0.914209302937996,
0.913163846516007, 0.776698687524975, 0.597284692104539, 0.91488961230643,
0.28945161773974, 0.282895617679457, 0.28492139335934, 0.928492227792593,
0.287740157404564, 0.93011080075256, 0.32787462005944, 0.809245564874419,
0.299095322129539, 0.302473955104931, 0.453458703894119, 0.331724139938735,
0.314265997270211, 0.378968117507553, 0.344955599135117, 0.961200295699775,
1.07300929383762, 0.339365254133058, 0.421999171190298, 0.351276824906379,
0.36810350819186, 0.364237601690115, 0.425751222495895, 1.2000504740503,
0.401585883450189, 0.393244206959102, 0.412013522316855, 1.40622761554481,
1.43010692801434, 1.45452312391606, 1.44102848262452, 0.583854512560274,
0.453530324821785, 0.836929179095723, 0.485649439571136, 1.45323622566975,
1.42066532567401, 1.55192692063172, 1.69545734226667, 1.59084952877426,
0.536277991651981, 0.878100994910164, 1.80588869793109, 0.612726668114702,
1.49557275883036, 1.83080789724595, 0.859368961826519, 1.3537163175202,
0.795003445956722, 1.68510799767645, 1.94219078558463, 0.678911636490617,
1.98538116097216, 1.39431924099171, 0.716178198907659, 0.897864731079577,
0.739754008960108, 1.32647638785145, 1.27550346512974, 1.57782298324095,
1.17541538713537, 1.08141388070016, 2.81373485339402, 0.841584582588819,
2.98872530454666, 1.93484656658214, 3.01625884992721, 0.902448663673698,
0.361944635028181, 1.03795562218241, 0.961881521906292, 0.704732279822006,
0.894256898010956, 0.307197052425753, 0.620230669033494, 0.900835004143219,
0.336503062729966, 0.376726235662507, 0.323019953443342, 0.291097473211189,
0.583926906347703, 0.540940525007957, 0.906358816314195, 0.372788957369332,
0.335375002309946, 0.914209302937996, 0.328320596067713, 0.659589829678685,
0.68859386616471, 0.91488961230643, 0.902977019532625, 0.739324647975471,
0.603576498397486, 0.690375139214112, 0.603004583921208, 0.659868379563069,
0.292376232645021, 0.562401086780579, 0.298131207627614, 0.299095322129539,
0.302473955104931, 0.705840069893102, 0.993644273952054, 0.425326528868129,
0.400345928302124, 0.361221494378293, 0.328750601711733, 0.55820945179875,
0.748093576785292, 0.345188978576, 0.351315165819748, 0.357626992140137,
0.517538802067647, 1.04751086637289, 0.385695811626645, 0.385612146149294,
0.397271280188057, 0.550298801906058, 1.28131889629393, 0.82396230266283,
1.03189532043667, 0.502923809446499, 1.13388533378536, 0.821249922028902,
0.496130920693478, 0.491056299113018, 0.861144623672965, 0.498763665924562,
0.912165347541201, 0.64869230436972, 1.32528603957948, 1.75339437114229,
1.78285803283739, 1.11217610098546, 0.597795159831033, 1.00740416004752,
0.739549658487185, 0.607139331936484, 1.35734916834937, 1.43608105985186,
1.80042779869959, 1.18905308118327, 1.70456429994882, 0.905541925940458,
2.22398340066076, 2.16944665030202, 2.29546486372867, 1.85605245367111,
1.1239234690604, 2.50480944519147, 1.02954245959557, 0.975126362552554,
2.14223132835323, 2.91282474285556, 2.66863827732602, 0.933593864631134,
2.70815814163342, 2.87351062547491, 0.335329222971355, 0.934907402460015,
0.57591904762801, 0.907224647738403, 0.320417497402957, 0.766767831651282,
0.861903342837008, 0.303464733511709, 0.709698376015027, 0.308598232977547,
0.293930575800507, 0.29130992351097, 0.28896933229556, 0.45769807141885,
0.468340431926149, 0.830040974016766, 0.282420179745874, 0.477428977916008,
0.733418492651481, 0.822348309121175, 0.280392410026905, 0.542239475756514,
0.281077879631808, 0.281845318148658, 0.42849080424256, 0.295089908538224,
0.747925637213591, 0.929814463524078, 0.310954657683433, 0.292376232645021,
0.64500798819687, 0.690255336889303, 0.364309565584761, 0.306129346468766,
0.311371964852598, 0.915461004824963, 0.397063771122394, 1.0404933625801,
0.483845551843616, 0.333807374425717, 0.402255447456447, 0.453946781602374,
0.394538152500142, 0.357626992140137, 0.364237601690115, 0.372020526598045,
0.37823224873185, 0.389581791596903, 0.393244206959102, 0.401126173348066,
0.563948059226945, 0.625538021242673, 0.80823517471131, 0.440809452269821,
0.753920921570439, 0.571583127323145, 0.463092290982252, 0.576935449307388,
0.482901053437729, 1.40965077473646, 1.25183016539419, 0.856169846501004,
1.72377824975207, 0.536277991651981, 1.13652692119597, 1.24290457699823,
1.64437171023011, 1.87302947654355, 0.594841647571458, 2.04410190051534,
1.62571002130845, 1.13052139459963, 0.836130011762252, 1.85233449007414,
2.38839794838805, 1.09920265799031, 1.94766079436355, 1.66770758466983,
1.27453119791191, 2.57917818578189, 1.13896219096471, 2.74804359878488,
1.69823856330245, 0.935150681359782, 1.74656095016161, 0.835168244061429,
0.841584582588819, 0.856635868155615, 0.972724285567558, 2.42939239419398,
0.96325679668782, 0.640892567004161, 1.03795562218241, 0.949309568900219,
0.316910844084317, 0.311204732481577, 0.307197052425753, 0.303464733511709,
0.779574150582344, 0.296830513889512, 0.335960010735195, 0.4390886067335,
0.28896933229556, 0.306902835898889, 0.926150657204963, 0.388532344331494,
0.495283643343666, 0.916064063737401, 0.281013296117892, 0.913163846516007,
0.912928724576721, 0.438926937515807, 0.59117658733228, 0.517844090756594,
0.704234100156676, 0.913848110190877, 0.423829975580762, 0.795497269555325,
0.289917958593354, 0.292376232645021, 0.295114252321699, 0.345353147959634,
0.854886103409894, 0.62965115658928, 0.776701146370991, 0.446059142229343,
0.326457042618417, 0.568752212327844, 0.325374322793979, 0.374762702815228,
0.333807374425717, 0.420206697512664, 0.399408381034396, 0.456977698650331,
0.357626992140137, 0.596680957599271, 1.29550961397828, 1.24265117031916,
0.580164026815441, 0.393244206959102, 0.401126173348066, 0.443462006528755,
0.417630422649225, 0.426247823064678, 0.505363855323395, 0.494595916530596,
1.12922054709106, 0.482617341273223, 0.650774092876326, 0.5452273225038,
1.61305811763483, 1.66701808699342, 0.514281824935098, 0.525174470147384,
1.6850349371761, 1.78354241230912, 1.83460579403794, 1.86582069105335,
1.40279004365455, 0.594841647571458, 0.691585610303159, 0.619623644706909,
2.06846657922012, 0.710726446010795, 0.997307890433014, 2.40064963745822,
2.22161516025196, 1.79188547652641, 2.19553900228869, 2.1816869110449,
2.1984531582332, 2.55364304827728, 0.918827215513173, 0.930267750935017,
0.798812034349413, 0.830829315142733, 1.13089106389005, 1.00204606351463,
1.07126361979325, 0.871799972892206, 1.28166129954517), .Dim = c(181L,
2L), .Dimnames = list(NULL, NULL), index = structure(c(699, 700,
701, 702, 703, 704, 705, 706, 707, 708, 709, 710, 711, 712, 713,
714, 715, 716, 717, 718, 719, 720, 721, 722, 723, 724, 725, 726,
727, 728, 729, 730, 731, 732, 733, 734, 735, 736, 737, 738, 739,
740, 741, 742, 743, 744, 745, 746, 747, 748, 749, 750, 751, 752,
753, 754, 755, 756, 757, 758, 759, 760, 761, 762, 763, 764, 765,
766, 767, 768, 769, 770, 771, 772, 773, 774, 775, 776, 777, 778,
779, 780, 781, 782, 783, 784, 785, 786, 787, 788, 789, 1065,
1066, 1067, 1068, 1069, 1070, 1071, 1072, 1073, 1074, 1075, 1076,
1077, 1078, 1079, 1080, 1081, 1082, 1083, 1084, 1085, 1086, 1087,
1088, 1089, 1090, 1091, 1092, 1093, 1094, 1095, 1096, 1097, 1098,
1099, 1100, 1101, 1102, 1103, 1104, 1105, 1106, 1107, 1108, 1109,
1110, 1111, 1112, 1113, 1114, 1115, 1116, 1117, 1118, 1119, 1120,
1121, 1122, 1123, 1124, 1125, 1126, 1127, 1128, 1129, 1130, 1131,
1132, 1133, 1134, 1135, 1136, 1137, 1138, 1139, 1140, 1141, 1142,
1143, 1144, 1145, 1146, 1147, 1148, 1149, 1150, 1151, 1152, 1153,
1154), class = "Date"), class = "zoo")
library(hydroTSM)
dm2seasonal(df, FUN=sum, season="DJF")
I've used the package hydroTSM. The package can also be used for other seasons (MAM, JJA, SON) and with other functions (e.g. mean). You can compute the yearly seasonal sums for every column in your matrix (df). seas does the same for every column, but you have to write your own loop to get yearly seasonal sums I guess. mkseas() from seas will compute the sum over all winter months in your timeseries.

R - How to perform cross-year date operations?

I am working with daily measurements of temperature. In total I have about 40 years of observations. How can I perform date operations covering a time interval that crosses years?
For example, I want to sum the values from every october-to-february period. However, the sum should be taken only on the contiguous period of oct-nov-dec-jan-feb.
"Isolated" months should not be taken into account, like for example jan and feb of the first year, and oct-nov-dec of the last year. The sum has to run over the contiguous period only (from oct-nov-dec-jan-fev).
For example, this is what I am looking for:
1st year 2nd year 3rd year
J-F-M-A-M-J-J-A-S-**O-N-D J-F**-M-A-M-J-J-A-S-**O-N-D J-F**-M-A-M-J-J-A-S-O-N-D
But this is not OK:
1st year 2nd year 3rd year
**J-F**-M-A-M-J-J-A-S-**O-N-D J-F**-M-A-M-J-J-A-S-**O-N-D J-F**-M-A-M-J-J-A-S-**O-N-D**
This is a sample data frame to work on:
df <- structure(list(date = structure(c(-3653, -3622, -3593, -3562,
-3532, -3501, -3471, -3440, -3409, -3379, -3348, -3318, -3287,
-3256, -3228, -3197, -3167, -3136, -3106, -3075, -3044, -3014,
-2983, -2953, -2922, -2891, -2863, -2832, -2802, -2771, -2741,
-2710, -2679, -2649, -2618, -2588, -2557, -2526, -2498, -2467,
-2437, -2406, -2376, -2345, -2314, -2284, -2253, -2223, -2192,
-2161, -2132, -2101, -2071, -2040, -2010, -1979, -1948, -1918,
-1887, -1857, -1826, -1795, -1767, -1736, -1706, -1675, -1645,
-1614, -1583, -1553, -1522, -1492, -1461, -1430, -1402, -1371,
-1341, -1310, -1280, -1249, -1218, -1188, -1157, -1127, -1096,
-1065, -1037, -1006, -976, -945, -915, -884, -853, -823, -792,
-762, -731, -700, -671, -640, -610, -579, -549, -518, -487, -457,
-426, -396, -365, -334, -306, -275, -245, -214, -184, -153, -122,
-92, -61, -31, 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304,
334, 365, 396, 424, 455, 485, 516, 546, 577, 608, 638, 669, 699,
730, 761, 790, 821, 851, 882, 912, 943, 974, 1004, 1035, 1065,
1096, 1127, 1155, 1186, 1216, 1247, 1277, 1308, 1339, 1369, 1400,
1430, 1461, 1492, 1520, 1551, 1581, 1612, 1642, 1673, 1704, 1734,
1765, 1795, 1826, 1857, 1885, 1916, 1946, 1977, 2007, 2038, 2069,
2099, 2130, 2160, 2191, 2222, 2251, 2282, 2312, 2343, 2373, 2404,
2435, 2465, 2496, 2526, 2557, 2588, 2616, 2647, 2677, 2708, 2738,
2769, 2800, 2830, 2861, 2891, 2922, 2953, 2981, 3012, 3042, 3073,
3103, 3134, 3165, 3195, 3226, 3256, 3287, 3318, 3346, 3377, 3407,
3438, 3468, 3499, 3530, 3560, 3591, 3621, 3652, 3683, 3712, 3743,
3773, 3804, 3834, 3865, 3896, 3926, 3957, 3987, 4018, 4049, 4077,
4108, 4138, 4169, 4199, 4230, 4261, 4291, 4322, 4352, 4383, 4414,
4442, 4473, 4503, 4534, 4564, 4595, 4626, 4656, 4687, 4717, 4748,
4779, 4807, 4838, 4868, 4899, 4929, 4960, 4991, 5021, 5052, 5082,
5113, 5144, 5173, 5204, 5234, 5265, 5295, 5326, 5357, 5387, 5418,
5448, 5479, 5510, 5538, 5569, 5599, 5630, 5660, 5691, 5722, 5752,
5783, 5813, 5844, 5875, 5903, 5934, 5964, 5995, 6025, 6056, 6087,
6117, 6148, 6178, 6209, 6240, 6268, 6299, 6329, 6360, 6390, 6421,
6452, 6482, 6513, 6543, 6574, 6605, 6634, 6665, 6695, 6726, 6756,
6787, 6818, 6848, 6879, 6909, 6940, 6971, 6999, 7030, 7060, 7091,
7121, 7152, 7183, 7213, 7244, 7274), class = "Date"), temp = c(22.9223529411765,
23.0705882352941, 23.1094117647059, 20.7835294117647, 17.4517647058824,
17.3176470588235, 18.0494117647059, 19.6188235294118, 21.3023529411765,
23.1105882352941, 22.2364705882353, 22.7482352941176, 23.5870588235294,
24.0023529411765, 23.0094117647059, 22.0176470588235, 19.4917647058824,
18.1011764705882, 18.3164705882353, 20.0623529411765, 22.8717647058824,
23.2576470588235, 23.68, 22.3694117647059, 22.9517647058824,
23.6976470588235, 23.3294117647059, 20.8564705882353, 18.16,
15.8988235294118, 15.7988235294118, 18.4176470588235, 20.8423529411765,
20.3247058823529, 22.3070588235294, 22.2035294117647, 24.2235294117647,
23.6976470588235, 24.4082352941176, 21.1752941176471, 18.1023529411765,
16.1211764705882, 18.3164705882353, 19.7635294117647, 23.1294117647059,
22.9964705882353, 23.6552941176471, 22.6964705882353, 23.6011764705882,
23.6517647058824, 23.7035294117647, 22.4352941176471, 18.5835294117647,
16.5976470588235, 15.7741176470588, 19.2541176470588, 20.8776470588235,
20.5729411764706, 21.1729411764706, 21.5870588235294, 22.4576470588235,
23.6058823529412, 21.84, 21.6694117647059, 19.2458823529412,
18.7517647058824, 17.7811764705882, 19.4764705882353, 21.9270588235294,
21.5470588235294, 22.88, 23.2458823529412, 24.2776470588235,
25.2470588235294, 23.4694117647059, 21.4435294117647, 19.3941176470588,
18.5447058823529, 17.6, 18.3764705882353, 19.8529411764706, 22.0823529411765,
22.7294117647059, 23.4011764705882, 23.3611764705882, 24.2505882352941,
23.2870588235294, 21.9482352941176, 20.5552941176471, 18.0788235294118,
18.5929411764706, 20.8752941176471, 21.9023529411765, 23.6105882352941,
22.4070588235294, 21.5635294117647, 23.3129411764706, 22.9741176470588,
23.3670588235294, 19.6105882352941, 16.9941176470588, 17.7670588235294,
17.4858823529412, 17.8517647058824, 20.26, 22.1576470588235,
23.8364705882353, 23.4447058823529, 24.8129411764706, 25.1764705882353,
24.2694117647059, 21.5035294117647, 20.0458823529412, 18.4694117647059,
18.4541176470588, 19.5388235294118, 22.02, 20.5364705882353,
22.9858823529412, 21.9752941176471, 23.7729411764706, 24.0576470588235,
24.0941176470588, 22.1552941176471, 21.2329411764706, 19.5611764705882,
17.8788235294118, 18.6823529411765, 20.1541176470588, 21.6258823529412,
21.5211764705882, 23.9811764705882, 24.8352941176471, 24.5882352941176,
24.1729411764706, 21.1035294117647, 19.0435294117647, 17.08,
17.4529411764706, 19.1458823529412, 20.4447058823529, 20.7129411764706,
21.5047058823529, 22.6952941176471, 23.4364705882353, 23.1, 24.1847058823529,
19.8105882352941, 19.9847058823529, 20.5188235294118, 17.7658823529412,
19.4435294117647, 20.7588235294118, 21.7835294117647, 22.7788235294118,
23.2388235294118, 24.9129411764706, 25.6, 23.5647058823529, 24.0058823529412,
19.7823529411765, 19.3152941176471, 18.7741176470588, 19.0305882352941,
20.5576470588235, 21.3611764705882, 21.4247058823529, 23.4811764705882,
23.6505882352941, 25.1870588235294, 23.3541176470588, 21.4823529411765,
18.7364705882353, 17.7235294117647, 18.3976470588235, 19.7235294117647,
21.0741176470588, 21.6094117647059, 22.9635294117647, 22.4011764705882,
23.4152941176471, 24.7741176470588, 24.3270588235294, 20.7976470588235,
18.8764705882353, 17.7788235294118, 16.4129411764706, 21.4117647058824,
22.3317647058824, 21.66, 22.3694117647059, 23.0917647058824,
24.4541176470588, 23.2847058823529, 23.3164705882353, 21.2529411764706,
19.1258823529412, 17.3882352941176, 17.3823529411765, 19.0529411764706,
19.6576470588235, 20.2976470588235, 21.9023529411765, 23.3094117647059,
24.0117647058824, 25.5611764705882, 24.9129411764706, 21.3964705882353,
19.9870588235294, 18.3929411764706, 20.9917647058824, 20.3058823529412,
21.4435294117647, 23.1941176470588, 22.8388235294118, 22.5176470588235,
24.6317647058824, 24.6541176470588, 24.2, 20.84, 18.4576470588235,
17.5011764705882, 19.16, 20.54, 20.1517647058824, 22.6776470588235,
22.7470588235294, 22.7882352941176, 22.0811764705882, 24.2152941176471,
22.9235294117647, 20.8411764705882, 19.6188235294118, 17.16,
16.0529411764706, 20.3223529411765, 19.9752941176471, 22.5152941176471,
22.2705882352941, 23.1541176470588, 23.1047058823529, 23.9517647058824,
24.8176470588235, 22.18, 20.5023529411765, 17.3505882352941,
19.1917647058824, 19.9894117647059, 19.0235294117647, 22.8235294117647,
22.7094117647059, 23.8741176470588, 24.0517647058824, 25.1764705882353,
23.9235294117647, 21.2929411764706, 20.6117647058824, 17.1305882352941,
16.3470588235294, 19.6470588235294, 21.3341176470588, 20.2176470588235,
23.7435294117647, 22.6741176470588, 22.9070588235294, 24.7152941176471,
23.2905882352941, 20.5776470588235, 18.9635294117647, 19.0658823529412,
18.8423529411765, 20.0729411764706, 21.3047058823529, 22.1588235294118,
24.0388235294118, 22.1917647058824, 24.0517647058824, 24.8729411764706,
23.0117647058824, 23, 21.3094117647059, 19.4105882352941, 20.3470588235294,
19.4482352941176, 20.0670588235294, 21.6364705882353, 23.4211764705882,
23.16, 25.4788235294118, 26.4741176470588, 24.0482352941176,
21.4176470588235, 21.7164705882353, 19.0905882352941, 19.6752941176471,
18.1611764705882, 20.0482352941176, 23.4917647058824, 23.4894117647059,
22.5482352941176, 23.1376470588235, 24.9811764705882, 24.1552941176471,
22.8423529411765, 19.7435294117647, 16.4, 17.3105882352941, 20.5235294117647,
21.0494117647059, 23.1352941176471, 23.9435294117647, 23.9058823529412,
24.9835294117647, 24.6952941176471, 24.0047058823529, 23.3164705882353,
21.5823529411765, 18.3447058823529, 18.1964705882353, 20.0035294117647,
20.7152941176471, 22.5705882352941, 24.6541176470588, 23.2329411764706,
25.0517647058824, 24.3329411764706, 23.5811764705882, 22.9988235294118,
19.4976470588235, 17.3188235294118, 19.5635294117647, 19.0211764705882,
19.7223529411765, 22.6858823529412, 23.9423529411765, 23.6905882352941,
25.7129411764706, 23.9505882352941, 24.4376470588235, 22.6070588235294,
19.8882352941176, 17.2058823529412, 16.4211764705882, 20.02,
21.9458823529412, 21.9341176470588, 22.74, 23.8, 23.9611764705882,
24.4564705882353, 24, 23.2129411764706, 19.4729411764706, 17.7105882352941,
16.9682352941176, 19.0341176470588, 20.2917647058824, 20.7776470588235,
22.9364705882353, 22.7894117647059)), .Names = c("date", "temp"
), row.names = c(NA, -360L), class = "data.frame")
Any input appreciated.
Hopefully this helps:
df$date = as.POSIXct(df$date,format="%Y-%m-%d")
df$year = as.numeric(format(df$date,format="%Y"))
df$month = as.numeric(format(df$date,format="%m"))
years = unique(df$year)
# initialize a new data frame to store in your summed values
newdf=NULL
# run through a loop starting at your second year and ending at second last
for(i in 2:(length(years)-1)){
#data from year1
start = df[df$year==years[i] & df$month %in% c(10,11,12),]
end = df[df$year==years[i+1] & df$month %in% c(1,2),]
data1 = rbind(start,end)
# in case you have NAs in your data you can add ra.rm = T
sum.data = sum(data1$temp,na.rm = T)
df1 = as.data.frame(list(Year = years[i],
sum.data = sum.data))
# or paste year 1 and year 2 together
#df1 = as.data.frame(list(Year = paste(years[i],years[i+1],sep="-"),
# sum.data = sum.data))
newdf = rbind(newdf,df1)
}
head(newdf)

Time Series based Forecasting for Daily Data but Seasonality is Quarterly - in R

I have demand for a product on daily bases for last 4 years. This demand has quarterly seasonal patterns, as shown in following image
I would like to do time series based forecasting on this data. Following is my code
myts = ts(forecastsku1$Value,frequency=90)
fit <- stl(myts, s.window="period")
plot(fit)
fit <- decompose(myts)
plot(fit)
Here instead of 4 seasonal factor ts is creating 90 seasonal factor, which is not what I want. I want to apply same seasonality on 3 month duration and then do forecasting.
Data for reference
dput(head(forecastsku1,100))
structure(list(date = structure(c(14625, 14626, 14627, 14628, 14629, 14630, 14631, 14632, 14633, 14634, 14635, 14636, 14637,
14638, 14639, 14640, 14641, 14642, 14643, 14644, 14645, 14646, 14647, 14648, 14649, 14650, 14651, 14652, 14653, 14654, 14655,
14656, 14657, 14658, 14659, 14660, 14661, 14662, 14663, 14664, 14665, 14666, 14667, 14668, 14669, 14670, 14671, 14672, 14673,
14674, 14675, 14676, 14677, 14678, 14679, 14680, 14681, 14682, 14683, 14684, 14685, 14686, 14687, 14688, 14689, 14690, 14691,
14692, 14693, 14694, 14695, 14696, 14697, 14698, 14699, 14700, 14701, 14702, 14703, 14704, 14705, 14706, 14707, 14708, 14709,
14710, 14711, 14712, 14713, 14714, 14715, 14716, 14717, 14718, 14719, 14720, 14721, 14722, 14723, 14724), class = "Date"),
Value = c(1407, 1413, 1407, 1406, 1401, 1410, 1411, 1416, 1404, 1409, 1414, 1414, 1400, 1421, 1398, 1404, 1397, 1404, 1407, 1409, 1406, 1395, 1397,
1403, 1412, 1399, 1409, 1393, 1405, 1403, 1406, 1402, 1405, 1386, 1393, 1405, 1397, 1393, 1402, 1402, 1393, 1391, 1410, 1402, 1408,
1394, 1404, 1398, 1406, 1389, 1401, 1391, 1394, 1384, 1377, 1390, 1395, 1399, 1384, 1397, 1398, 1384, 1377, 1394, 1398, 1394, 1391,
1403, 1382, 1390, 1385, 1403, 1390, 1388, 1391, 1384, 1392, 1390, 1381, 1387, 1395, 1390, 1388, 1384, 1387, 1395, 1380, 1378, 1383,
1384, 1232, 1247, 1232, 1248, 1236, 1236, 1231, 1237, 1224, 1236)),
.Names = c("date", "Value"), row.names = 13150:13249, class = "data.frame")
Can anyone help me in this case? Please let me know if more data required.
myts = ts(forecastsku1$Value,frequency=4)
fit <- decompose(myts)
plot(fit)
Result would be:
It is creating a 90 seasonal factor because your frequency is 90 in the ts definition. What you need to do is to specify a start and end in the ts and the period=4 so that the observations can be segregated the way you want them to be.. if you can successfully create a 4 seasonal factor, you can obviousy predict quarterly (4*3=12) . So instead of these dates I think it is more clear to have like start=c(2005,1) .Hopefully this is useful
this is an old question, but still, maybe my answer is of some value.
You can seasonally adjust daily data using the dsa package (disclaimer: I'm the author).
I tried to replicate your time series (or something similar) to give you an idea of how to seasonally adjust them (the setting of the seasonal adjustment try to help modelling the jumping behaviour of the time series appropriately):
# loading packages
library(dsa); library(xts)
# Replication of the data
set.seed(23)
data <- seq(1250, 1000, , length.out=365.25*4) + rnorm(365.25*4, 0, 5)
time <- seq(as.Date("2008-01-01"), by="days", length.out=365.25*4)
x <- xts(data, time)
ind <- as.numeric(format(zoo::index(x), "%m")) # Indicator of day of year
x[ind==1 | ind==2 | ind==3 | ind==7 | ind==8 | ind==9] <-
x[ind==1 | ind==2 | ind==3 | ind==7 | ind==8 | ind==9] + 200
# Seasonally adjusting the data
result <- dsa(x, fourier_number=40, reiterate3=4, reg.create=NULL, cval=30)
sa <- result$output[,1]
xtsplot(result$output[,c(2,1)], names=c("original", "seasonally adjusted"))
output(result) # creates a html in your working directory.

Resources