Related
Does anyone know why this multiple regression model's visualization fails?
This is not a syntax error or typo. I think I missed something, but don't know what's the missing part.
> Oct_Mar %>% model(lm(ctr ~ view + price_view + cart + price_cart +
> purchase + price_purchase)) %>% forecast(new_data(Oct_Mar, 30) %>%
> autoplot(Oct_Mar)
Error throws as below
#MULTIPLE LINEAR REGRESSION MODEL
##############################################################
library(stats)
library(tidyverse)
#Da es sich bei den Daten des ausgewählten Datenset um Panel Data handelt nutze ich das Multiple Regression Model lm_Oct_Mar <- lm(ctr ~ view + price_view + cart + price_cart + purchase + price_purchase, data=Oct_Mar) summary(lm_Oct_Mar)
Fit.consMR <- lm(ctr ~ view + price_view + cart + price_cart + purchase + price_purchase, data=Oct_Mar)
#ctr=1.844e-02 + -7.330e-09*view + 1.010e-07*price_view + 1.639e-088*cart + -2.222e-07*price_cart + 3.302e-07*purchase + -4.157e-07*price_purchase
```
structure(list(date = c("2019.10.01", "2019.10.02", "2019.10.03",
"2019.10.04", "2019.10.05", "2019.10.06", "2019.10.07", "2019.10.08",
"2019.10.09", "2019.10.10", "2019.10.11", "2019.10.12", "2019.10.13",
"2019.10.14", "2019.10.15", "2019.10.16", "2019.10.17", "2019.10.18",
"2019.10.19", "2019.10.20", "2019.10.21", "2019.10.22", "2019.10.23",
"2019.10.24", "2019.10.25", "2019.10.26", "2019.10.27", "2019.10.28",
"2019.10.29", "2019.10.30", "2019.10.31", "2019.11.01", "2019.11.02",
"2019.11.03", "2019.11.04", "2019.11.05", "2019.11.06", "2019.11.07",
"2019.11.08", "2019.11.09", "2019.11.10", "2019.11.11", "2019.11.12",
"2019.11.13", "2019.11.14", "2019.11.15", "2019.11.16", "2019.11.17",
"2019.11.18", "2019.11.19", "2019.11.20", "2019.11.21", "2019.11.22",
"2019.11.23", "2019.11.24", "2019.11.25", "2019.11.26", "2019.11.27",
"2019.11.28", "2019.11.29", "2019.11.30", "2019.12.01", "2019.12.02",
"2019.12.03", "2019.12.04", "2019.12.05", "2019.12.06", "2019.12.07",
"2019.12.08", "2019.12.09", "2019.12.10", "2019.12.11", "2019.12.12",
"2019.12.13", "2019.12.14", "2019.12.15", "2019.12.16", "2019.12.17",
"2019.12.18", "2019.12.19", "2019.12.20", "2019.12.21", "2019.12.22",
"2019.12.23", "2019.12.24", "2019.12.25", "2019.12.26", "2019.12.27",
"2019.12.28", "2019.12.29", "2019.12.30", "2019.12.31", "2020.01.01",
"2020.01.02", "2020.01.03", "2020.01.04", "2020.01.05", "2020.01.06",
"2020.01.07", "2020.01.08", "2020.01.09", "2020.01.10", "2020.01.11",
"2020.01.12", "2020.01.13", "2020.01.14", "2020.01.15", "2020.01.16",
"2020.01.17", "2020.01.18", "2020.01.19", "2020.01.20", "2020.01.21",
"2020.01.22", "2020.01.23", "2020.01.24", "2020.01.25", "2020.01.26",
"2020.01.27", "2020.01.28", "2020.01.29", "2020.01.30", "2020.01.31",
"2020.02.01", "2020.02.02", "2020.02.03", "2020.02.04", "2020.02.05",
"2020.02.06", "2020.02.07", "2020.02.08", "2020.02.09", "2020.02.10",
"2020.02.11", "2020.02.12", "2020.02.13", "2020.02.14", "2020.02.15",
"2020.02.16", "2020.02.17", "2020.02.18", "2020.02.19", "2020.02.20",
"2020.02.21", "2020.02.22", "2020.02.23", "2020.02.24", "2020.02.25",
"2020.02.26", "2020.02.27", "2020.02.28", "2020.02.29", "2020.03.01",
"2020.03.02", "2020.03.03", "2020.03.04", "2020.03.05", "2020.03.06",
"2020.03.07", "2020.03.08", "2020.03.09", "2020.03.10", "2020.03.11",
"2020.03.12", "2020.03.13", "2020.03.14", "2020.03.15", "2020.03.16",
"2020.03.17", "2020.03.18", "2020.03.19", "2020.03.20", "2020.03.21",
"2020.03.22", "2020.03.23", "2020.03.24", "2020.03.25", "2020.03.26",
"2020.03.27", "2020.03.28", "2020.03.29", "2020.03.30", "2020.03.31"
), price_view = c(35.79, 180.16, 437.57, 10.3, 74.26, 79.8, 89.84,
121.24, 461.95, 142.06, 241.71, 52, 43.24, 41.16, 167.05, 764.06,
91.64, 189.82, 38.59, 152.64, 86.23, 321.33, 411.83, 256.88,
352.39, 76.32, 360.11, 123.53, 43.41, 149.38, 14.16, 489.07,
1661.74, 1253.07, 25.71, 154.42, 990.89, 1645.93, 144.12, 84.43,
240.25, 148.18, 41.13, 262.56, 168.78, 860.85, 239.31, 372.98,
165.64, 134.32, 20.7, 43.73, 765.76, 51.48, 599.49, 893.79, 155.29,
334.37, 46.82, 1814.72, 196.27, 1302.48, 40.16, 1161.68, 381.48,
184.48, 48.91, 221.11, 434.73, 149.27, 77.22, 882.49, 106.05,
669.23, 282.86, 179.67, 12.97, 460.24, 38.59, 278.26, 243.76,
1904.79, 84.93, 32.18, 25.71, 496.54, 29.6, 1466.83, 164.33,
234.76, 19.95, 308.37, 1130.02, 7.47, 79.8, 65.9, 746.45, 1347.78,
1270.82, 69.42, 231.41, 195.6, 715.33, 208.47, 720.46, 414.68,
24.45, 217.82, 434.45, 483.92, 1500.42, 318.15, 339.29, 267.45,
133.85, 9.03, 11.81, 280.57, 916.74, 58.51, 339.78, 33.98, 263.58,
19.31, 239.88, 489.07, 84.92, 344.9, 95.24, 99.1, 142.58, 480.58,
104.74, 14.83, 252, 1039.41, 28.3, 328.97, 341.55, 278.26, 43.73,
91.35, 102.32, 131.25, 155.15, 77.74, 14.67, 132.63, 1185.36,
1145.975, 1106.59, 849.42, 117.63, 171.32, 167.31, 252.23, 248.14,
111.15, 257.15, 27.62, 169.86, 101.89, 282.89, 298.57, 86.49,
196.32, 1415.45, 898.35, 334.6, 17.99, 13.62, 566.27, 60.41,
36.34, 62.04, 308.81, 32.95, 127.44, 836.57, 221.34, 360.34,
159.31, 20.57), view = c(1206151, 1152770, 1087372, 1344804,
1270060, 1262993, 1159265, 1323522, 1301376, 1240347, 1445162,
1432321, 1583572, 1376274, 1462409, 1443323, 1337174, 1413405,
1382403, 1443838, 1342668, 1353053, 1318395, 1252747, 1369922,
1288939, 1330209, 1220710, 1187883, 1169955, 1207854, 1402754,
1513400, 1524803, 1743304, 1670637, 1644359, 1748812, 1789808,
1783142, 1845552, 1907417, 1892753, 1920411, 2864410, 5691766,
5986292, 5759703, 1905351, 1627672, 1598554, 1573101, 1471242,
1474138, 1500022, 1496128, 1557252, 1547199, 1560191, 1727852,
1644405, 1706901, 1629904, 1547658, 1468085, 1540157, 1652208,
1725106, 1724452, 1627222, 1651328, 1605421, 1650612, 1634861,
1760750, 2167056, 2875847, 2780816, 2665285, 2528244, 2387520,
2340327, 2471739, 2372930, 2326654, 2322753, 2240514, 2058141,
2089081, 2474226, 2294820, 1603749, 1427733, 1700904, 1765457,
1754424, 1738774, 1696188, 1701769, 1585870, 1556542, 1557542,
1618230, 1645866, 1627433, 1612956, 1555416, 1773179, 1826768,
2021676, 2104199, 1801073, 1733142, 1593991, 1645225, 1557626,
1637470, 1721003, 1545472, 1594688, 1565742, 1651606, 1999670,
2217825, 1985751, 1680034, 1608904, 1620473, 1628906, 1726835,
1589058, 1714745, 1751044, 1896265, 2429526, 2268487, 1935249,
1916034, 2239698, 1916650, 1981570, 1948648, 1987134, 1749514,
1822349, 1830307, 1748590, 1734610, 1798308, 1399256, 1000204,
1257475, 1770064, 2416707, 2477258, 2487470, 2457500, 2210539,
2377633, 2026050, 2301337, 2218894, 2012789, 1700619, 1481115,
1562027, 1560348, 1338829, 1244973, 1142989, 1260747, 1316975,
1387394, 1319559, 1440470, 1451015, 1439649, 1390411, 1336076,
1369834, 1255626, 1244163, 1283731), price_cart = c(29.51, 1415.48,
99.86, 358.57, 617.51, 1052.79, 1747.79, 190.56, 128.28, 252.38,
250.91, 720.48, 33.42, 643, 191.77, 460.11, 408.5, 789.9, 577.94,
49.36, 380.7, 19.56, 994.86, 756.71, 223.66, 437.33, 1684.28,
366.16, 968.34, 1683.07, 550.77, 503.09, 29.09, 179.67, 210.62,
22.66, 131.66, 68.96, 360.06, 494.22, 1023.62, 1569.92, 28.29,
694.97, 127.05, 37.85, 282.89, 178.9, 913.28, 1022.42, 424.7,
573.7, 1029.34, 30.12, 20.82, 17.99, 107.53, 41.19, 85.82, 1002.55,
140.98, 167.03, 231.67, 25.71, 205.64, 30.81, 51.22, 65.9, 7.08,
308.63, 227.79, 16.22, 7.89, 62.52, 48.88, 586.63, 602.07, 1312.26,
128.32, 179.9, 849.42, 100.9, 1284.2, 12.84, 128.42, 59.18, 176.99,
38.02, 48.88, 694.54, 262.3, 1402.84, 1453.18, 3.84, 453.01,
76.93, 7.04, 865.93, 865.4, 40.75, 1423.07, 1534.66, 679.27,
11.25, 102.63, 436.3, 853.93, 694.97, 850.47, 477.49, 1234.97,
10.27, 23.94, 643.23, 89.84, 290.34, 320.99, 6.44, 140.28, 188.89,
56.88, 1326.31, 194.34, 140.28, 771.96, 140.03, 20.21, 1464.39,
59.18, 57.92, 1156.81, 50.43, 300.12, 38.1, 832.71, 57.91, 174.5,
100.36, 248.14, 109.34, 100.7, 242.7, 266.67, 592.01, 242.18,
22.66, 566.04, 38.61, 812.06, 490.33, 168.6, 172.03, 49.91, 16.73,
108.04, 347.47, 97.79, 111.15, 514.79, 126.1, 178.87, 870.03,
529.31, 43.5, 2110.48, 771.94, 15.32, 105.25, 7.14, 312.67, 61.75,
165.51, 48.37, 643.49, 303.48, 35.78, 154.42, 209.71, 76.69,
25.46, 1415.45, 123.53, 602.31), cart = c(16658, 17268, 19323,
43826, 35493, 32145, 18052, 18442, 18432, 18997, 21450, 20691,
24833, 44821, 49513, 45272, 40368, 40127, 39455, 40533, 36675,
36945, 36407, 35721, 36800, 34776, 34256, 17838, 17455, 16996,
16798, 18911, 19350, 20211, 21960, 19231, 19670, 19446, 77319,
70093, 71585, 75135, 69669, 71613, 170183, 481862, 405584, 426261,
83117, 72450, 72311, 75530, 70171, 64801, 68099, 71405, 71622,
71324, 71504, 92345, 81760, 84473, 80869, 70192, 66718, 71048,
83618, 84231, 80773, 80675, 81420, 78947, 80162, 82360, 86689,
109721, 183764, 155406, 146906, 137487, 127900, 124577, 127381,
126700, 124797, 127554, 123966, 120940, 127769, 148663, 148608,
119062, 57614, 71342, 95608, 80629, 78782, 79099, 77396, 74671,
72772, 74827, 72221, 73406, 72999, 71182, 70235, 79414, 104791,
103481, 102597, 94354, 90666, 83642, 83223, 73075, 73582, 73849,
70067, 71600, 72179, 130757, 208231, 169156, 137970, 116560,
104701, 102836, 101145, 101605, 90864, 92635, 95114, 100283,
158447, 131720, 118661, 126405, 132399, 98277, 96270, 95284,
96886, 89046, 91384, 89585, 83771, 83241, 84151, 62362.5, 40574,
48944, 81869, 146953, 135144, 132819, 134255, 131648, 141696,
122204, 122752, 120927, 112159, 102239, 95998, 97600, 99032,
79662, 76622, 69585, 73822, 74488, 75621, 69098, 73761, 76429,
75664, 77671, 77090, 77835, 68888, 69091, 73986), price_purchase = c(130.76,
419.6, 251.74, 252.88, 64.02, 272.59, 172.72, 88.81, 28.73, 1003.86,
346.47, 130.48, 29.86, 280.11, 358.57, 385.83, 287.61, 22.95,
58.08, 854.08, 28.28, 62.91, 994.86, 51.22, 9.01, 77.21, 244.15,
366.16, 366.8, 213.25, 35.52, 566.3, 35.78, 1106.82, 64.35, 722.18,
131.66, 166.1, 823.9, 138.23, 334.6, 328.19, 243.51, 488.8, 159.57,
106.8, 54.03, 27, 308.63, 1022.42, 463.31, 144.66, 44.53, 25.48,
126.18, 365.52, 133.92, 97.27, 12.84, 1002.55, 107.41, 132.31,
131.2, 789.57, 230.2, 12.36, 229.86, 1386.91, 154.19, 18.19,
76.96, 882.49, 191.55, 46.08, 24.17, 102.65, 326.62, 924.06,
923.73, 88.29, 41.16, 128.42, 326.88, 137.96, 30.68, 108.88,
181.19, 241.34, 128.32, 137.46, 1279.81, 643.23, 1275.16, 717.245,
159.33, 745.37, 288.27, 177.26, 168.58, 66.85, 331.51, 437.31,
643.23, 9.3, 0.85, 436.3, 105.51, 7.7, 79.44, 1321.37, 160.89,
107.21, 172.25, 514.79, 141.06, 900.64, 153.22, 924.4, 176.34,
94.98, 162.6, 1326.25, 39.9, 38.15, 2162.22, 180.95, 153.41,
720.48, 720.48, 15.42, 140.28, 514.02, 720.47, 174.7, 197.69,
411.08, 741.07, 230.12, 501.89, 109.34, 643.26, 23.17, 242.48,
1317.36, 69.76, 178.11, 153.55, 32.18, 812.06, 482.7, 153.34,
172.03, 128.68, 939.54, 108.04, 165.89, 56.63, 43.76, 171.17,
98.59, 21.95, 280.28, 181.47, 730.01, 159.31, 60.75, 31.15, 1412.39,
7.14, 942.84, 321.06, 165.51, 284.95, 169.42, 303.48, 224.3,
416.43, 385.85, 492.08, 334.6, 1415.45, 123.53, 308.55), purchase = c(19307,
19469, 19255, 27041, 23494, 22171, 21378, 23072, 22748, 21993,
26224, 25373, 29561, 28405, 26372, 31394, 28318, 25850, 24657,
25098, 25167, 25385, 24731, 23999, 23929, 22653, 23403, 21112,
20374, 20817, 20099, 22458, 21864, 22145, 26889, 24875, 25319,
24863, 25714, 22768, 22878, 24931, 22725, 22548, 22124, 45185.5,
68247, 185195, 28537, 24967, 24947, 25266, 24187, 22243, 23163,
24827, 24226, 24443, 24305, 32107, 28178, 28345, 28548, 24358,
24473, 25469, 27505, 27012, 25766, 26802, 27059, 25906, 26044,
26712, 26559, 35077, 63796, 51899, 49578, 48212, 46405, 44255,
44719, 46602, 44917, 44949, 44154, 43081, 45287, 49597, 50729,
38233, 3574, 13975.5, 24377, 28938, 28427, 28875, 27722, 27510,
26492, 27481, 26059, 25869, 27525, 26322, 27121, 29614, 35086,
32884, 32548, 32619, 31698, 30089, 30398, 27579, 26662, 26880,
27052, 26841, 27403, 27612, 33750, 32536, 32308, 28645, 27652,
28276, 28533, 28426, 25379, 26027, 46480, 60013, 102117, 83216,
76048, 72365, 87586, 63260, 36377, 31438, 31258, 29324, 28946,
29017, 27884, 28063, 27809, 27649.5, 27490, 26316, 31358, 55087,
46356, 45228, 44406, 43521, 45501, 40281, 41091, 41681, 39266,
36268, 34754, 35341, 35943, 28852, 27810, 25186, 25501, 26232,
25775, 23698, 25314, 25960, 26259, 27487, 26966, 25817, 21294,
22704, 23997), ctr = c(0.0157890561813006, 0.0166396305077271,
0.0173986509381537, 0.0194731497951218, 0.0179954394804347, 0.01711863909483,
0.0181582360570687, 0.0171927115779559, 0.0172358403646591, 0.0174638541971058,
0.0178806664612045, 0.017462347179514, 0.0183790774089859, 0.0199881077619723,
0.0174426987635606, 0.021089685240109, 0.0205569049800296, 0.0177842661874661,
0.0173413941476575, 0.0169081718788632, 0.0182456430344012, 0.0182626162052032,
0.0182543279386951, 0.0186259961442581, 0.0170104683085926, 0.0171132003490177,
0.0171517774365777, 0.0170457664943143, 0.016903142521019, 0.0175382134561578,
0.0164120092891695, 0.0157969704536582, 0.014264557168488, 0.0143332034531726,
0.0152322825367764, 0.0147200846456646, 0.0152154800186776, 0.0140607309566817,
0.0137719608789332, 0.0122855439272407, 0.0119334194687182, 0.0125752060979989,
0.01158007808718, 0.0113191407332442, 0.00729059877222415, 0.00731911608538772,
0.0106771470535411, 0.029937936916542, 0.0143512493034839, 0.0146854166936255,
0.0149305898441825, 0.015325442746133, 0.015691446743994, 0.0144534643673336,
0.0147711815606066, 0.0158382630541111, 0.0148728508159624, 0.015102040564144,
0.0148955533969277, 0.0176392994824187, 0.0163240478169816, 0.0158230497930639,
0.0166871934499785, 0.0150557839107457, 0.0159453688844757, 0.0158074236363467,
0.0158454822084702, 0.0149292254566175, 0.0142730130593139, 0.0156929838274791,
0.0156162350209032, 0.0153802494466767, 0.0150476029799385, 0.015555365325721,
0.0143761174252573, 0.0154064275947974, 0.0208510166815324, 0.0176754346231314,
0.0176296702464377, 0.01808584587117, 0.0184482114318881, 0.0179540460804964,
0.0172054387638893, 0.0186435592467685, 0.0183226179107802, 0.0183442319676677,
0.0186738733252132, 0.0197702609494553, 0.0204285359857455, 0.0189093019186096,
0.0207614056972417, 0.0221922195760301, 0.00240617175649865,
0.00788575626634226, 0.01309841408011, 0.0157695717780358, 0.0156402333683254,
0.0162649757475833, 0.0155814665868539, 0.0165668899473124, 0.0162596037350689,
0.0168350415867981, 0.0154154128099543, 0.0150464847912372, 0.0161870630522126,
0.0156293605393382, 0.0166831626222356, 0.0159851624182969, 0.0181646017543342,
0.0154736802975027, 0.0147489845006063, 0.0172093148404027, 0.0173801189598905,
0.0179353887292393, 0.017586875624838, 0.0169123585500959, 0.0155822266067893,
0.0149761651657073, 0.0167448758587691, 0.0161082597966258, 0.0167303551270177,
0.0154917937591837, 0.015286011465188, 0.0136306070303869, 0.0152129210946259,
0.0159440585908669, 0.0161367409642245, 0.0164079686231546, 0.016492577386447,
0.0155465861608803, 0.0151072490270382, 0.0144004027929932, 0.0251766100192941,
0.0300583807652007, 0.0394582941939502, 0.0346703430162482, 0.0370259651104479,
0.0354306787130485, 0.0369234479028471, 0.0313956783546004, 0.0175071227813499,
0.0153811379243536, 0.0149988963637585, 0.0159494386911496, 0.0151254119566314,
0.0151138709885764, 0.0152175253675449, 0.015437458845637, 0.0147726989007463,
0.02059282, 0.0264129334017437, 0.0201436139554002, 0.0169325780144314,
0.0214876387664511, 0.0177445890793224, 0.0172606914733451, 0.017133563936406,
0.0185813515317095, 0.0180607614170281, 0.0187505760492009, 0.0169511102933927,
0.0178137558385877, 0.0184785698285323, 0.0201169476464591, 0.0220364679005246,
0.0212945438945016, 0.021660499704709, 0.0203399246100257, 0.021042755155702,
0.0207706911083365, 0.0191080416224264, 0.0188521002714409, 0.0176177277744931,
0.0170654092407268, 0.0167173964870618, 0.0169957130997929, 0.0173290930652611,
0.018723068602435, 0.0190819762151085, 0.0178334964691514, 0.0160768402598991,
0.0172883539665594, 0.0176745227466401)), row.names = c(NA, -183L
), class = "data.frame")
This question already has answers here:
Subsetting data.table set by date range in R
(3 answers)
Subset a dataframe between 2 dates
(8 answers)
Closed 4 years ago.
structure(list(id = c(14735, 11589, 1165, 7864, 9151, 6662, 26, 6638, 7635, 10204, 10588, 11923, 2119, 2487, 11571, 6759, 9591,
1592, 12725, 5086, 3039, 10576, 2526, 1127, 583, 12879, 5686, 13405, 1375, 7547, 11479, 9220, 8040, 13848, 14996, 4256, 1879,
2653, 15220, 1896, 4547, 2505, 1105, 3625, 10896, 9806, 1154, 2626, 2215, 5957, 3522, 8531, 8867, 1501, 2415, 14009, 13056,
13740, 1751, 540, 8896, 4771, 8457, 5383, 2176, 8611, 5072, 1828, 3884, 5364, 12617, 11887, 14267, 12735, 2261, 8962, 12501, 9586,
7129, 3925, 373, 4987, 3410, 13304, 10276, 7975, 8456, 3752, 111, 14384, 10901, 4234, 11273, 13196, 5764, 10902, 3631, 9814,
14781, 5726), full_date = structure(c(1522781128, 1522108662, 1519981076, 1521121363, 1521457099, 1520859176, 1519631141, 1520856439,
1521056830, 1521753388, 1521853223, 1522173544, 1520160750, 1520238731, 1522105027, 1520873428, 1521581248, 1520074992, 1522326287, 1520600253,
1520300281, 1521850210, 1520242830, 1519972727, 1519776890, 1522350676, 1520695451, 1522446321, 1520025013, 1521042071, 1522085537, 1521481296,
1521154393, 1522521269, 1522939333, 1520464381, 1520117285, 1520254658, 1523208654, 1520119807, 1520509952, 1520241232, 1519954606, 1520375033,
1521937117, 1521645125, 1519978700, 1520252273, 1520176769, 1520750012, 1520362171, 1521290786, 1521377710, 1520061816, 1520221068, 1522546134,
1522389100, 1522506558, 1520098043, 1519764349, 1521384566, 1520541898, 1521271618, 1520642366, 1520169730, 1521307430, 1520598946, 1520109560,
1520416134, 1520639385, 1522308872, 1522167432, 1522609927, 1522327583, 1520186995, 1521399556, 1522283646, 1521580399, 1520947600, 1520421124, 1519712304, 1520583404, 1520349813, 1522426307, 1521776496, 1521143409,
1521271618, 1520395530, 1519645678, 1522639423, 1521939121, 1520461036, 1522043512, 1522409242, 1520707332, 1521939139, 1520376024, 1521647387,
1522804886, 1520700876), class = c("POSIXct", "POSIXt"), tzone = "UTC"),
real_time = c("18:45:28", "23:57:42", "8:57:56", "13:42:43",
"10:58:19", "12:52:56", "7:45:41", "12:7:19", "19:47:10",
"21:16:28", "1:0:23", "17:59:4", "10:52:30", "8:32:11", "22:57:7",
"16:50:28", "21:27:28", "11:3:12", "12:24:47", "12:57:33",
"1:38:1", "0:10:10", "9:40:30", "6:38:47", "0:14:50", "19:11:16",
"15:24:11", "21:45:21", "21:10:13", "15:41:11", "17:32:17",
"17:41:36", "22:53:13", "18:34:29", "14:42:13", "23:13:1",
"22:48:5", "12:57:38", "17:30:54", "23:30:7", "11:52:32",
"9:13:52", "1:36:46", "22:23:53", "0:18:37", "15:12:5", "8:18:20",
"12:17:53", "15:19:29", "6:33:32", "18:49:31", "12:46:26",
"12:55:10", "7:23:36", "3:37:48", "1:28:54", "5:51:40", "14:29:18",
"17:27:23", "20:45:49", "14:49:26", "20:44:58", "7:26:58",
"0:39:26", "13:22:10", "17:23:50", "12:35:46", "20:39:20",
"9:48:54", "23:49:45", "7:34:32", "16:17:12", "19:12:7",
"12:46:23", "18:9:55", "18:59:16", "0:34:6", "21:13:19",
"13:26:40", "11:12:4", "6:18:24", "8:16:44", "15:23:33",
"16:11:47", "3:41:36", "19:50:9", "7:26:58", "4:5:30", "11:47:58",
"3:23:43", "0:52:1", "22:17:16", "5:51:52", "11:27:22", "18:42:12",
"0:52:19", "22:40:24", "15:49:47", "1:21:26", "16:54:36")), row.names = c(NA, -100L), class = c("tbl_df", "tbl", "data.frame"))
I want to filter above data and find observations that happened between two hours, let's say 09:30:00 and 16:15:30. What's the best way to do that, maybe with lubridate or hms packages?
As I said in comments this can be solved such as
start_data = "18:45:28"
end_date = "19:45:28"
# df - your data.frame
df[df$real_time > start_data & df$real_time < end_date , ]
Output:
id full_date real_time
26 12879 2018-03-29 19:11:16 19:11:16
51 3522 2018-03-06 18:49:31 18:49:31
73 14267 2018-04-01 19:12:07 19:12:7
75 2261 2018-03-04 18:09:55 18:9:55
76 8962 2018-03-18 18:59:16 18:59:16
I would like to plot the SAT dataset found here
https://blog.prepscholar.com/sat-percentiles-high-precision-2016
My issue with doing this is that I am unsure if there is a more elegant way to do this than I am doing. Currently, I am converting those percentiles to Z scores and then using that associated probability to create a distribution. The problem that I have is
The SAT scores do not seem to be normally distributed. They approximate a normal distribution, but they do not seem to be normally distributed. This makes using the tried and true rnorm (X, mean = 1000, sd = 200) unusable.
I am not sure if there is a better way than converting the percentiles to Z scores since the SAT scores do not seem to be normally distributed.
Any help would be appreciated.
My long term plan is to create a shiny ap where a person can use a slider to move along the distribution to see where their score puts them in what percentile. But the first step is to actually figure out a way to produce an accurate distribution.
Here is the code in total:
scores <- as.numeric(
c(
1600, 1593, 1587, 1580, 1573, 1567,
1560, 1553, 1547, 1540, 1533, 1527,
1520, 1513, 1507, 1500, 1493, 1487,
1480, 1473, 1467, 1460, 1453, 1447,
1440, 1433, 1427, 1420, 1413, 1407,
1400, 1393, 1387, 1380, 1373, 1367,
1360, 1353, 1347, 1340, 1333, 1327,
1320, 1313, 1307, 1300, 1293, 1287,
1280, 1273, 1267, 1260, 1253, 1247,
1240, 1233, 1227, 1220, 1213, 1207,
1200, 1193, 1187, 1180, 1173, 1167,
1160, 1153, 1147, 1140, 1133, 1127,
1120, 1113, 1107, 1100, 1093, 1087,
1080, 1073, 1067, 1060, 1053, 1047,
1040, 1033, 1027, 1020, 1013, 1007,
1000, 0993, 0987, 0980, 0973, 0967,
0960, 0953, 0947, 0940, 0933, 0927,
0920, 0913, 0907, 0900, 0893, 0887,
0880, 0873, 0867, 0860, 0853, 0847,
0840, 0833, 0827, 0820, 0813, 0807,
0800, 0793, 0787, 0780, 0773, 0767,
0760, 0753, 0747, 0740, 0733, 0727,
0720, 0713, 0707, 0700, 0693, 0687,
0680, 0673, 0667, 0660, 0653, 0647,
0640, 0633, 0627, 0620, 0613, 0607,
0600, 0593, 0587, 0580, 0573, 0567,
0560, 0553, 0547, 0540, 0533, 0527,
0520, 0513, 0507, 0500, 0493, 0487,
0480, 0473, 0467, 0460, 0453, 0447,
0440, 0433, 0427, 0420, 0413, 0407,
0400
)
)
probs <- as.numeric(
c(
0.000665335, 0.001508711, 0.002067932, 0.002878073, 0.003976493, 0.005137125,
0.006483906, 0.008169371, 0.010066473, 0.012051019, 0.014095858,
0.016307247, 0.01851226, 0.020808986, 0.023364025, 0.02601564,
0.028721866, 0.031560739, 0.034551519, 0.037733663, 0.041036965,
0.044427406, 0.047928757, 0.051538726, 0.055292787, 0.059145645,
0.063187376, 0.067367682, 0.071691308, 0.076255174, 0.080943422,
0.085690142, 0.090464868, 0.095379534, 0.100511283, 0.105758358,
0.111083521, 0.116571178, 0.122285078, 0.128123463, 0.13397113,
0.139830118, 0.145699225, 0.151666124, 0.157793404, 0.164023115,
0.170358704, 0.17676173, 0.183278673, 0.189955902, 0.196651135,
0.203363202, 0.210071134, 0.216801722, 0.223562248, 0.230347853,
0.237183732, 0.243934459, 0.250657665, 0.257436698, 0.264227682,
0.270968969, 0.277599004, 0.284165141, 0.290648753, 0.297040829,
0.303401865, 0.30964291, 0.315714288, 0.321696268, 0.3275473,
0.33324613, 0.338771004, 0.344104024, 0.34924206, 0.354185931,
0.358956451, 0.363504804, 0.36782396, 0.371962147, 0.375851065,
0.37943538, 0.382754048, 0.38580143, 0.388568593, 0.391025026,
0.393142417, 0.394947023, 0.39643261, 0.397582763, 0.398388967,
0.398835641, 0.398933788, 0.398676885, 0.398065535, 0.397089484,
0.395745285, 0.394041326, 0.391951596, 0.389478503, 0.386655445,
0.383491062, 0.379943329, 0.376014793, 0.371758542, 0.367167906,
0.362242796, 0.356970877, 0.351398549, 0.345499578, 0.33929925,
0.332851353, 0.326122779, 0.31911459, 0.311858166, 0.304408822,
0.296767961, 0.288895933, 0.280893084, 0.272865458, 0.264642129,
0.256259902, 0.247931807, 0.239607, 0.231228792, 0.222875786,
0.214544714, 0.206273084, 0.198003801, 0.189731661, 0.181671447,
0.173826196, 0.16610093, 0.158499433, 0.151067478, 0.143751108,
0.136558209, 0.129683746, 0.123040703, 0.11660098, 0.110455988,
0.104559737, 0.098857524, 0.093254931, 0.087923914, 0.08286171,
0.077907056, 0.073124914, 0.068583012, 0.064242767, 0.059980362,
0.055906234, 0.052062062, 0.048298984, 0.044678669, 0.041258641,
0.03796372, 0.034841037, 0.03185105, 0.028992313, 0.026330747,
0.023870486, 0.0215867, 0.019418127, 0.017379035, 0.015436224,
0.01358768, 0.011905384, 0.01032104, 0.008865584, 0.007564083,
0.006380472, 0.005299104, 0.004317991, 0.003512008, 0.00284036,
0.002268168, 0.001724469, 0.001327348, 0.001030367, 0.000112
)
)
data <- as.data.frame (cbind (scores, probs))
data2 <- sample (data$scores, 10000000, replace = T, prob = data$probs)
den <- density (data2, adjust = 2)
plot (den , xlim = c(400,1600))
I have the following problem. Basically I have data, that follows the Gregorian calendar and data, which follows a 360 day calendar and a 365 day calendar (no leap years). Its a feature of the Model, which provides the data. I only could create a timeindex for data with a 360 or 365 day calendar with the help of library(PCICt), therefore the timeindex is of class PCICt and not class date for those data sets with 360d or 365d calendars.
I managed to change the class of the timeindex of data with a 365 day calendar easily, because it always missed the 29th February. Overall it has less days than data with a Gregorian calendar, thats why the following code worked:
index(Modellwind.IPSL.1971_2100.mat.5.zoo) <- as.Date(paste(index(Modellwind.IPSL.1971_2100.mat.5.zoo), "%Y-%m-%d"))
class(index(Modellwind.IPSL.1971_2100.mat.5.zoo))
any(is.na(Modellwind.IPSL.1971_2100.mat.5.zoo))
I could merge data with a Gregorian calendar with data with a 365 day calendar (Modellwind.IPSL.1971_2100.mat.5.zoo has a 360d calendar) with the following code:
library(zoo)
library(PCICt)
Mergedata.Gregorian_cal.365d_cal <- merge(Modellwind.1971_2100.mat.5.zoo[,1],Modellwind.IPSL.1971_2100.mat.5.zoo[,1], fill = NA)
sum(is.na(Mergedata.Gregorian_cal.365d_cal)) #Gives you the number of leap years between the starting date and end date. Between 1971 and 2100, you have 32 leap years.
The problem is, that the 360 day calendar has 30 days per month. Because the 30th February doesnt exist, I cant use the method above. Is there the possibility to use the index of the data set with a Gregorian calendar, to mask the days in the data with a 360 days calendar, which arent present in the data with a Gregorian calendar? I would have NA for the 31th for each month in the data with a 360 day calendar, which has 31 days and the 30th of February would always be excluded/"deleted".
Example data for the year 1972 for all these 2 calendar types. 1972 is a leap year.
Data with Gregorian calendar:
structure(c(18.0824119718086, 22.0984972927228, 15.6444417189609,
5.89666444009656, 18.1725165479582, 21.9512885928156, 4.88193965506205,
13.933395151291, 13.0150555148858, 12.2412020084762, 15.1707058527428,
11.9102181846508, 11.8373087451369, 4.88134153024087, 3.9195944541078,
8.15191977152853, 16.4878972832708, 22.3388856060094, 24.9339938808775,
9.40486557731387, 3.28778357417694, 5.4431969404311, 20.9010729191345,
21.576769300227, 23.5252763396514, 18.7725442737342, 19.7400816746119,
16.9286422645386, 11.5214494652195, 12.6356049638603, 7.8885628659944,
7.81687922456664, 4.76970848125104, 4.71443717941174, 4.3332862268629,
5.39949220500925, 17.2259740635503, 8.94893163333614, 10.5413637024979,
7.17270151460124, 13.1168987701018, 7.80375818376942, 9.19842495123789,
6.50186468363422, 2.72654917702192, 4.76044540462425, 9.33231780065151,
2.94546305078892, 4.67014980066904, 23.8062593679947, 20.0513022569902,
17.0747102447771, 22.1857749192152, 16.3213003571625, 5.59820337769238,
11.7719699596263, 2.80575446040357, 6.01800547567089, 8.40297112483879,
11.8088715968982, 4.98554106381165, 4.57889903991417, 5.46723000525948,
2.2046248257294, 6.50476062233784, 5.93160587570127, 2.66548923257402,
6.18402932922427, 6.90886137443288, 3.85090651354255, 8.24126904737149,
10.9654562975344, 26.2730566456532, 20.7006666233841, 6.82182724533744,
12.9025799024923, 9.59995956664874, 18.3086576464973, 8.53427988021107,
13.5057006787102, 2.58426562914531, 4.77444858313551, 4.01236032427182,
11.972201385, 19.541507043929, 12.7122726666622, 6.58520942950129,
10.0492820845097, 5.32566668447011, 2.57782664078923, 7.15092309537708,
13.5172698318347, 14.9398233030208, 14.5222484425227, 8.00143290635926,
11.5258287774697, 6.38313299466099, 1.79298307790425, 4.16626735598483,
10.4754961358211, 7.29533307327725, 6.14846988554932, 12.0495274648323,
5.53397133979113, 8.37782693478431, 7.52399322022154, 13.8764650137859,
10.9413294317165, 5.79402371881772, 7.61939719880655, 2.01218529630289,
4.15345219536974, 9.53346680530963, 14.4880341424594, 6.6395383447145,
12.2147086716578, 8.61151331855143, 4.96406162861823, 2.31444711425824,
9.18479155288269, 14.0394170749205, 12.9045375342084, 8.56014631714993,
4.45030804438492, 4.54819424494151, 9.14814577436106, 9.0203698734204,
6.67536854576542, 9.86685350667901, 15.9765223111542, 1.99936492761379,
6.05549611543566, 8.26375285688692, 12.5235986676351, 15.753125460594,
12.8737600421306, 16.0142537420495, 19.6491102126186, 8.91315893820258,
5.75924709992013, 8.67418792548294, 8.36985128360697, 10.5301033184449,
7.51027331456462, 5.64433360963038, 8.25879595299386, 11.1260560553349,
7.56823816330665, 4.03999047793942, 2.81275010350658, 7.50072029786943,
6.58751650188931, 4.69084765180419, 2.37774148302349, 0.88406335422542,
1.27681388119446, 7.38546258354973, 7.36477953003889, 3.58214484416496,
9.33399864014572, 9.33384978115708, 3.75564662489672, 5.86615895989352,
11.3163675166137, 8.89088851209378, 4.83661603649021, 11.4775955585757,
8.10159661929649, 9.25168563140256, 16.8836969171831, 6.71441561265801,
8.94010341793042, 7.48206041367068, 7.85296846107665, 4.56322967848792,
3.94854955874465, 9.03935129713431, 6.80925025513715, 5.46249642897673,
2.72994386661837, 5.81781746717527, 3.58557872362357, 2.65017962257611,
10.9264114121261, 25.1233976430826, 10.9044779304577, 6.34084805815993,
13.2469244191216, 12.5438867673809, 6.69512144534366, 7.9716973798577,
6.42699271186533, 7.34127100087814, 9.48351531950429, 3.731756550704,
2.97235842074357, 9.33755238371563, 8.45534306181479, 9.76758605452981,
7.10973204410344, 5.58659570577684, 6.73065557918815, 2.2443822565949,
10.0324385505791, 12.4468029449543, 8.54955485805234, 7.74625286400315,
8.76361852142208, 7.31040726702086, 10.9069555344467, 20.2240593355273,
18.8325145078602, 13.8646347231803, 6.18721686089014, 5.06959205667858,
1.88326841118378, 3.46887269480676, 10.466733322762, 10.0359820698446,
11.6007096598598, 9.40090116780089, 9.33769236702315, 9.95757914421451,
8.55990604010644, 10.4960731180582, 15.1722236227608, 11.1686532067003,
12.5359489386538, 9.08166190238287, 3.05025798629833, 8.2121249493627,
13.5877493909831, 17.366136605839, 10.1228300566323, 8.27402110802059,
9.36245413432149, 8.46450110123141, 1.84281651654745, 3.30160338329847,
6.3138195121321, 11.728173138611, 10.6622626897554, 16.4094777741508,
20.0381278953011, 19.9861861731441, 14.5139852521008, 5.48642303877599,
7.72640073447677, 6.40813436142624, 1.68384368141763, 4.77881376279741,
5.18058883352236, 2.98929028921609, 4.63220103226812, 4.16738796400037,
13.0532771268428, 7.3104783906477, 2.22615400974864, 2.64542408728002,
7.21256528138117, 14.5616168774743, 6.49359376934273, 1.80947777511883,
1.05548742272005, 10.0100349138233, 12.9534450881407, 7.3887732493981,
2.06346550336316, 8.31717299234876, 7.78924597525132, 2.52953776616571,
8.82704926761683, 17.6640298084431, 13.3475985590147, 17.628200973858,
21.7018534179796, 18.5008930385254, 10.1186544078028, 20.3816253684839,
24.926808778224, 21.9880227371171, 20.1845589773564, 16.8169067228104,
10.2309882726068, 11.1248083859065, 20.5125621219226, 16.2733638505053,
18.8559651435026, 9.34653256821625, 16.1736806222654, 15.2975717551524,
14.5146239904197, 5.49088884606638, 10.6410636803798, 23.2390025461356,
17.9439644921709, 30.2719783889658, 17.8897458886807, 21.8089336705463,
21.181790238746, 7.74189585366475, 15.5669977526734, 22.2278845648006,
24.8537097755812, 23.4403701940983, 21.6831582162925, 2.51132630151019,
5.92677645017391, 10.9441543623409, 2.36029949616021, 1.16606557900293,
3.50793234808807, 9.61440088811323, 14.137409810834, 18.381771312848,
12.6572683827955, 18.797705699369, 20.8717521227799, 20.2278258689499,
12.9121727366459, 12.4660577833913, 19.7783723336818, 21.467091272057,
19.825201185869, 21.5289275033657, 25.2513848648435, 19.3231430907612,
14.4548913656037, 18.1364925154159, 25.6372229193355, 10.7132780942731,
3.39420618551996, 18.5659343284766, 21.7217416658684, 18.5067855518246,
17.6834051522095, 15.6325986696431, 11.6100239010514, 15.0764596715006,
8.46048294087618, 19.6747151949836, 10.0466139442861, 7.41836369302161,
19.4712502377319, 15.3111265245001, 6.54184803095167, 3.95906471757932,
4.6122997606339, 7.13881563394315, 2.48477412801708, 6.19131168025857,
7.82629557777152, 8.93410147891196, 6.27319459383102, 4.05195951965034,
8.77535610150876, 8.45968682510812, 6.27599562509301, 5.11571448525756,
1.68865280924914, 14.4333064594824, 20.5250630694977, 24.0600954370164,
13.4110946493079, 2.92078462265695, 9.06322147728374), index = structure(c(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, 790, 791, 792, 793, 794, 795,
796, 797, 798, 799, 800, 801, 802, 803, 804, 805, 806, 807, 808,
809, 810, 811, 812, 813, 814, 815, 816, 817, 818, 819, 820, 821,
822, 823, 824, 825, 826, 827, 828, 829, 830, 831, 832, 833, 834,
835, 836, 837, 838, 839, 840, 841, 842, 843, 844, 845, 846, 847,
848, 849, 850, 851, 852, 853, 854, 855, 856, 857, 858, 859, 860,
861, 862, 863, 864, 865, 866, 867, 868, 869, 870, 871, 872, 873,
874, 875, 876, 877, 878, 879, 880, 881, 882, 883, 884, 885, 886,
887, 888, 889, 890, 891, 892, 893, 894, 895, 896, 897, 898, 899,
900, 901, 902, 903, 904, 905, 906, 907, 908, 909, 910, 911, 912,
913, 914, 915, 916, 917, 918, 919, 920, 921, 922, 923, 924, 925,
926, 927, 928, 929, 930, 931, 932, 933, 934, 935, 936, 937, 938,
939, 940, 941, 942, 943, 944, 945, 946, 947, 948, 949, 950, 951,
952, 953, 954, 955, 956, 957, 958, 959, 960, 961, 962, 963, 964,
965, 966, 967, 968, 969, 970, 971, 972, 973, 974, 975, 976, 977,
978, 979, 980, 981, 982, 983, 984, 985, 986, 987, 988, 989, 990,
991, 992, 993, 994, 995, 996, 997, 998, 999, 1000, 1001, 1002,
1003, 1004, 1005, 1006, 1007, 1008, 1009, 1010, 1011, 1012, 1013,
1014, 1015, 1016, 1017, 1018, 1019, 1020, 1021, 1022, 1023, 1024,
1025, 1026, 1027, 1028, 1029, 1030, 1031, 1032, 1033, 1034, 1035,
1036, 1037, 1038, 1039, 1040, 1041, 1042, 1043, 1044, 1045, 1046,
1047, 1048, 1049, 1050, 1051, 1052, 1053, 1054, 1055, 1056, 1057,
1058, 1059, 1060, 1061, 1062, 1063, 1064, 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), class = "Date"), class = "zoo")
Data with 360 day calendar:
structure(c(16.2042726556084, 5.54411632675392, 8.39523962307452,
12.9056155820263, 2.61097842984656, 5.36226881021485, 6.11436671091439,
7.80097325957491, 2.6959250785196, 1.21734133687523, 9.83094824076473,
14.6123034310063, 22.5841804523832, 18.878943978969, 21.5918638597738,
21.6111797366467, 12.163190670239, 13.0688120229195, 13.1780838331026,
10.4636228871236, 24.5866766742838, 17.6333887432414, 13.5573702722517,
9.98750262602645, 6.60239076617993, 7.99851427184562, 10.7241814973962,
2.59032350802315, 11.0385501186685, 15.0489298603359, 8.01940878027097,
8.69182806695981, 16.4062789963677, 23.1456317293811, 26.5321804559772,
23.0561436633882, 26.6478272830746, 26.6213654159103, 17.8004617644568,
18.8721032889994, 19.0042310175412, 21.9278326697278, 20.3999804074965,
21.9715743408936, 18.1198929013236, 20.8010363608164, 16.2125640673085,
22.7866237759357, 25.7292529258921, 19.9958794890251, 18.256654841611,
26.5258848098581, 19.3699454096059, 10.2084937593693, 7.09411455312409,
11.1030076686983, 11.1372661762985, 3.46190062236435, 5.55418460608178,
7.97804690731097, 5.74135886926954, 7.37374922730165, 21.7072129639493,
22.3394149773537, 17.3029303467921, 3.78355687861244, 8.13184139976328,
5.59325194224167, 9.29484012593814, 6.31433046860712, 8.99969159771701,
12.9220576129017, 13.5931259265605, 3.13177632385839, 7.32634431180194,
3.65530722032479, 7.76414703436829, 8.81357616532502, 14.9915407274787,
15.6823286541919, 21.5504858786041, 5.98962336278648, 9.25806031602314,
15.3209102337594, 4.04377735300356, 5.57011616118502, 3.48142109034957,
3.33545016672156, 7.59622387150862, 6.33767973617138, 7.16777319213806,
11.6789745144836, 7.23398806122294, 8.42213573928181, 11.3854021290453,
8.0042725442433, 11.5874660430518, 7.59304392685827, 10.1325170959459,
9.43772890502225, 10.7429797911477, 8.98128618812878, 6.14861396465088,
3.3215569997678, 1.89256021088976, 7.7206472451583, 5.95522013274502,
1.70416254271118, 3.19059648186347, 12.7030870584645, 8.26968478768532,
6.41344157071221, 5.87633507183265, 5.49327509833653, 7.25912268522123,
14.1030446717508, 10.3857928070863, 1.78946477125607, 2.19269825383753,
5.36239917538602, 8.04801122336692, 9.13772174676138, 8.76030055066657,
5.24974918237121, 6.78870121691905, 6.33999578227359, 5.30281113218906,
3.30221973820352, 2.60392067446298, 1.53111462102273, 6.46313647857284,
5.41150103883632, 7.30461939054954, 1.31915479430045, 9.9035310971835,
17.5782680328385, 6.84670227987107, 6.11975680612864, 5.41175515673305,
1.96524773901671, 8.72579457176407, 14.8123207565971, 12.3543611734912,
12.5322670823202, 7.31607993610375, 4.88025074826665, 9.2349041842484,
12.8681772530755, 11.6570687183401, 11.3849275808392, 5.08995224957851,
11.7893280264097, 12.0657931400087, 3.90848586347189, 6.66831144616517,
13.0856694686881, 9.54256465111552, 12.8039726978337, 10.5409569683412,
6.2013575567933, 6.76347346611077, 8.01227281098426, 6.67880581810349,
1.87696959195576, 4.26549311170547, 6.0882073470888, 6.12735098378745,
3.77616335435411, 3.75627711831876, 2.42781407431047, 2.27015239785359,
8.49280126151322, 6.3855458158828, 7.55076769935463, 2.31943333528733,
8.61089385566335, 4.14893952705846, 7.1125243515635, 10.093324208137,
12.8925732478462, 8.38797653985974, 7.47214225316014, 3.01447415423619,
3.1124918239105, 0.997851709938026, 3.09921928374142, 6.93293196431786,
7.36267778624579, 1.6137886634392, 7.42809062139576, 10.1127101736776,
7.53648374651043, 9.3498729537249, 5.98534661771884, 3.62870605159867,
3.53073240568869, 10.6964068541091, 11.3646789054076, 13.6494798740885,
9.76353695866836, 4.1270448976489, 7.18525843242649, 14.6971093432512,
14.6412126138519, 10.3400082940444, 12.7842963215163, 15.0888363759895,
15.6640254377632, 7.23691815389075, 8.81381770055476, 10.4784236463785,
6.23389999515105, 9.40862295199213, 13.041974380848, 7.75158030116834,
10.6893999091349, 16.1456445166579, 14.9041082855705, 11.884570665801,
6.53019503138492, 8.45239632750322, 3.7455743269618, 7.12180323764388,
6.61415344272644, 8.13149697512074, 9.36721511760265, 6.95717437071885,
5.73006255663904, 11.0494713342971, 11.328774774157, 12.1912982708966,
7.22849562327449, 12.1251543738353, 8.31581645241497, 17.9662467445553,
20.7050537175761, 9.36158364710033, 11.3278809607471, 7.33435422138495,
3.10786053234989, 5.33073248829936, 9.06872903556503, 15.8831247239495,
15.2818041038765, 9.50926214591815, 5.15112388784473, 13.1166042461675,
21.3933111639123, 14.7608935887845, 6.08300197048536, 2.54102181247197,
11.0248978300555, 13.0216530977284, 12.6537314347268, 16.8215177071213,
18.1193743387326, 13.8658700430018, 2.87800172912917, 7.58969180535585,
15.6024741775647, 20.569775255989, 14.0528170625014, 9.86770039714737,
10.2081826678756, 5.37219506560582, 8.56141023229151, 9.91834375772563,
12.82212567194, 10.7507818184859, 4.15008765939222, 10.2404428622595,
3.80299439427962, 5.16901081513056, 4.4821661216413, 3.26656062260985,
4.43932965953986, 8.945663203153, 11.3165820526751, 20.8820331492001,
9.98917730606554, 7.55099134175274, 10.4150732881417, 13.2278295764203,
18.1688812620581, 14.1445620735261, 7.14736599655615, 13.2825680960019,
10.5791362373343, 10.8624315112779, 3.18344179431185, 7.49282700058505,
3.78157726350635, 9.96252691997304, 1.69077529836405, 6.67608715745644,
8.37990533734929, 4.20384964117427, 5.22889608012721, 7.8723594660963,
10.730029899683, 8.71664305274389, 4.20979088561725, 3.52386084017096,
7.40856535483994, 12.443352765902, 20.7950248202659, 14.0565344682657,
10.6669381116444, 13.6952498263664, 10.8380984642682, 6.35440732733458,
6.21954204111649, 4.00264648285958, 6.4317520226467, 2.2138115795096,
10.0540395919999, 11.1985829579804, 8.64327410338962, 0.556794049508732,
9.48036917584758, 18.9665686951357, 7.15010318217892, 1.70873116069864,
1.21720094748041, 5.19714843377925, 4.99390365971832, 5.54013921379378,
13.3190512627493, 15.4757059675959, 8.75635769236328, 5.07204433360002,
12.249854335649, 10.8985837736471, 5.39261907053974, 5.873209320872,
10.1689314517544, 16.4360884583216, 21.6810293369496, 14.8433120903617,
5.17306215960223, 8.97856967874759, 15.9031088669131, 7.59291974356731,
3.0192136898866, 10.3889800705301, 8.73409967642436, 9.31468756611007,
13.4058554846685, 8.53438382105245, 14.3729573721071, 18.6696075241301,
8.33988152577507, 7.42672203446524, 1.28062769400986, 8.37801485190093,
10.8397879874016, 8.72028550374256, 0.580257801954223, 4.39712796914426,
7.84989207801702), index = structure(c(62208000, 62294400, 62380800,
62467200, 62553600, 62640000, 62726400, 62812800, 62899200, 62985600,
63072000, 63158400, 63244800, 63331200, 63417600, 63504000, 63590400,
63676800, 63763200, 63849600, 63936000, 64022400, 64108800, 64195200,
64281600, 64368000, 64454400, 64540800, 64627200, 64713600, 64800000,
64886400, 64972800, 65059200, 65145600, 65232000, 65318400, 65404800,
65491200, 65577600, 65664000, 65750400, 65836800, 65923200, 66009600,
66096000, 66182400, 66268800, 66355200, 66441600, 66528000, 66614400,
66700800, 66787200, 66873600, 66960000, 67046400, 67132800, 67219200,
67305600, 67392000, 67478400, 67564800, 67651200, 67737600, 67824000,
67910400, 67996800, 68083200, 68169600, 68256000, 68342400, 68428800,
68515200, 68601600, 68688000, 68774400, 68860800, 68947200, 69033600,
69120000, 69206400, 69292800, 69379200, 69465600, 69552000, 69638400,
69724800, 69811200, 69897600, 69984000, 70070400, 70156800, 70243200,
70329600, 70416000, 70502400, 70588800, 70675200, 70761600, 70848000,
70934400, 71020800, 71107200, 71193600, 71280000, 71366400, 71452800,
71539200, 71625600, 71712000, 71798400, 71884800, 71971200, 72057600,
72144000, 72230400, 72316800, 72403200, 72489600, 72576000, 72662400,
72748800, 72835200, 72921600, 73008000, 73094400, 73180800, 73267200,
73353600, 73440000, 73526400, 73612800, 73699200, 73785600, 73872000,
73958400, 74044800, 74131200, 74217600, 74304000, 74390400, 74476800,
74563200, 74649600, 74736000, 74822400, 74908800, 74995200, 75081600,
75168000, 75254400, 75340800, 75427200, 75513600, 75600000, 75686400,
75772800, 75859200, 75945600, 76032000, 76118400, 76204800, 76291200,
76377600, 76464000, 76550400, 76636800, 76723200, 76809600, 76896000,
76982400, 77068800, 77155200, 77241600, 77328000, 77414400, 77500800,
77587200, 77673600, 77760000, 77846400, 77932800, 78019200, 78105600,
78192000, 78278400, 78364800, 78451200, 78537600, 78624000, 78710400,
78796800, 78883200, 78969600, 79056000, 79142400, 79228800, 79315200,
79401600, 79488000, 79574400, 79660800, 79747200, 79833600, 79920000,
80006400, 80092800, 80179200, 80265600, 80352000, 80438400, 80524800,
80611200, 80697600, 80784000, 80870400, 80956800, 81043200, 81129600,
81216000, 81302400, 81388800, 81475200, 81561600, 81648000, 81734400,
81820800, 81907200, 81993600, 82080000, 82166400, 82252800, 82339200,
82425600, 82512000, 82598400, 82684800, 82771200, 82857600, 82944000,
83030400, 83116800, 83203200, 83289600, 83376000, 83462400, 83548800,
83635200, 83721600, 83808000, 83894400, 83980800, 84067200, 84153600,
84240000, 84326400, 84412800, 84499200, 84585600, 84672000, 84758400,
84844800, 84931200, 85017600, 85104000, 85190400, 85276800, 85363200,
85449600, 85536000, 85622400, 85708800, 85795200, 85881600, 85968000,
86054400, 86140800, 86227200, 86313600, 86400000, 86486400, 86572800,
86659200, 86745600, 86832000, 86918400, 87004800, 87091200, 87177600,
87264000, 87350400, 87436800, 87523200, 87609600, 87696000, 87782400,
87868800, 87955200, 88041600, 88128000, 88214400, 88300800, 88387200,
88473600, 88560000, 88646400, 88732800, 88819200, 88905600, 88992000,
89078400, 89164800, 89251200, 89337600, 89424000, 89510400, 89596800,
89683200, 89769600, 89856000, 89942400, 90028800, 90115200, 90201600,
90288000, 90374400, 90460800, 90547200, 90633600, 90720000, 90806400,
90892800, 90979200, 91065600, 91152000, 91238400, 91324800, 91411200,
91497600, 91584000, 91670400, 91756800, 91843200, 91929600, 92016000,
92102400, 92188800, 92275200, 92361600, 92448000, 92534400, 92620800,
92707200, 92793600, 92880000, 92966400, 93052800, 93139200, 93225600
), cal = "360", months = c(30, 30, 30, 30, 30, 30, 30, 30, 30,
30, 30, 30), class = "PCICt", dpy = 360, tzone = "GMT", units = "secs"), class = "zoo")
I am not familiar with 360 day calendar, but the 360-day calender's index seems an epoch-second with the origin of 1970-01-01 in Gregorian Calendar. If this is the case this code will work.
library(data.table)
library(dplyr)
date <- attr(vec360, "index") %>% as.numeric() %>% as.POSIXct(origin="1970-01-01") %>% as.Date()
dt360 <- data.table(vec360, date)
date <- attr(vec365, "index")
dt365 <- data.table(vec365, date)
merged <- merge(dt360, dt365, all = T)
print(merged)
# date vec360 vec365
# 1: 1971-12-22 16.204273 NA
# 2: 1971-12-23 5.544116 NA
# 3: 1971-12-24 8.395240 NA
# 4: 1971-12-25 12.905616 NA
# 5: 1971-12-26 2.610978 NA
# ---
# 372: 1972-12-27 NA 20.525063
# 373: 1972-12-28 NA 24.060095
# 374: 1972-12-29 NA 13.411095
# 375: 1972-12-30 NA 2.920785
# 376: 1972-12-31 NA 9.063221
# get a zoo object back
merged_zoo <- zoo(merged)
Please make sure to check that the epoch second in the index of 360-day vector has the the origin of 1970-01-01.
In an effort to subset an xts object, I am using the .index* family of functions (http://www.inside-r.org/packages/cran/xts/docs/indexClass) as shown in one of the answers to this question: Return data subset time frames within another timeframes?.
The sample xts object used in this example has 1000 hourly data points from 2015-12-29 to 2016-02-29. The code below attempts to create subsets for various time selection criteria. Some of the functions are not working: indexyear, indexweek, indexday and indexmin fail to produce any output (please note the rest of the functions work as intended). Would anyone know why? Thanks very much!
library(xts)
DATSxts <- structure(c(1069.4, 1070.7, 1070.4, 1070.3, 1068.7, 1068.7, 1069.4, 1069.7, 1069.5, 1068.1, 1069.3, 1069.2, 1069.3, 1070.7, 1070.9, 1070.7, 1070.8, 1070.5, 1070.5, 1069.7, 1068.9, 1070.2, 1067.3, 1067.8, 1067.9, 1061.7, 1060.8, 1061.7, 1060.9, 1060.2, 1060.9, 1061, 1060.3, 1061.2, 1061.9, 1062, 1061.9, 1062.5, 1062.3, 1062.3, 1062, 1062.7, 1063, 1062, 1062.6, 1062.4, 1061.8, 1058.9, 1061.5, 1062.4, 1061.4, 1060.9, 1062, 1060.6, 1059.4, 1060.5, 1061.3, 1063.1, 1064.6, 1063.5, 1064.3, 1063.7, 1065.3, 1068.7, 1069.8, 1071.3, 1072.8, 1073.8, 1072.9, 1072.7, 1072.6, 1078.8, 1080.6, 1078.2, 1073.7, 1076.4, 1075.2, 1075.4, 1075.4, 1074.7, 1073.2, 1076, 1076.5, 1076.2, 1077.1, 1077.6, 1078.5, 1079.1, 1077, 1077, 1078.1, 1077.7, 1080, 1079.7, 1075.6, 1077.2, 1077.2, 1080, 1080, 1078.8, 1079, 1078.9, 1077.8, 1078, 1077.7, 1076.1, 1077, 1078.4, 1078.6, 1079.5, 1080.5, 1082.1, 1083.3, 1083.5, 1085.6, 1085.2, 1088.8, 1085.1, 1090.5, 1088, 1091.1, 1091.4, 1094.3, 1094.4, 1094.2, 1094.1, 1093.1, 1093.1, 1097.6, 1098.7, 1098.2, 1100.1,
1099.4, 1100.1, 1097.6, 1096.1, 1097, 1096.4, 1098.5, 1100.8, 1101.8, 1106.4, 1103.5, 1106.4, 1109.5, 1108.7, 1110.4, 1109.8, 1109.5, 1109.9, 1109.1, 1104.3, 1105.2, 1104.1, 1103.5, 1104, 1102.9, 1101.7, 1099.8, 1096.8, 1098.6, 1100, 1100.1, 1100, 1101.9, 1103.7, 1103.8, 1101.2, 1098.9, 1103.1, 1104.6, 1104.9, 1107.2, 1107.1, 1106.1, 1105.2, 1104.5, 1104.4, 1105.6, 1107.4, 1106.7, 1100.8, 1100, 1104.4, 1103.4, 1104, 1101.4, 1102, 1100, 1098.9, 1099.6, 1097.3, 1096.8, 1095.4, 1094.5, 1096.3, 1095.4, 1095.8, 1096, 1097.4, 1098.4, 1096.3, 1095, 1095.4, 1096.9, 1095.4, 1092.3, 1091.6, 1087.8, 1089, 1085.8, 1088.8, 1086.8, 1086.8, 1087.5, 1090.3, 1090, 1086.8, 1087.1, 1086.6, 1086.2, 1085, 1084.4, 1083.9, 1085.7, 1085.9, 1082.9, 1082.7, 1081.7, 1082.7, 1083.3, 1083.2, 1082.2, 1088.7, 1089.5, 1092.4, 1091.6, 1093, 1094.4, 1095.2, 1094.1, 1095.8, 1094.5, 1093.1, 1093.7, 1093.1, 1095.4, 1092.3, 1091.5, 1089.1, 1092.5, 1092.4, 1091.4, 1092.3, 1086.1, 1084.8, 1088.7, 1082.9, 1082.6, 1078.4, 1073.6, 1076.9, 1077.6, 1079.1, 1077.7, 1078.6, 1078.8, 1080.4, 1081.2, 1081.5, 1081.1, 1083.6, 1084.9, 1084.2, 1083.9, 1081.3, 1082.4, 1084.6, 1094.6, 1094.1, 1091.1, 1090.7, 1090.8, 1090.3, 1089.3, 1088.8, 1089.4, 1091, 1091.5, 1091.9, 1093.3, 1092.4, 1093.1, 1090.9, 1090.6, 1091, 1089.3, 1091.8, 1091.2, 1090.5, 1091, 1090.6, 1089.8, 1089.7, 1090.1, 1089.7, 1089.3, 1089.1, 1086.4, 1090.6, 1090.3, 1089, 1089.3, 1089.5, 1090.8, 1093.3, 1089.5, 1087.8, 1084.7, 1085.3, 1086.7, 1086.8, 1086.9, 1087.7, 1090.1, 1090.8, 1088.3, 1087.9, 1088.1, 1088.6, 1090.1, 1092.2, 1091.6, 1093.3, 1093.3, 1091.9, 1092.7, 1094.8, 1096.3, 1094.1, 1095.5, 1095.9, 1102.5, 1100.5, 1101.9, 1102.8, 1104.3, 1106.8, 1105.6, 1104.5, 1102.7, 1101.8, 1100.4, 1099.7, 1100.7, 1100.3, 1100.9, 1103, 1104.3, 1103.8, 1104.1, 1101.4, 1099.7, 1098.3, 1100.2, 1100.6, 1098.6, 1097.2, 1095.7, 1095.4, 1096, 1101.8, 1101.6, 1103.5, 1102.2, 1101.7, 1100.3, 1100.4, 1100.1, 1102.1, 1100.6, 1099.8, 1099.5, 1097.8, 1096.4, 1098.1, 1098.7, 1099.1, 1098.9, 1096.2, 1097.3, 1101.3, 1100, 1099, 1097, 1097.8, 1098.8, 1099, 1099.1, 1099.3, 1101.3, 1102.1, 1102.9, 1103.1, 1101.9, 1102.3, 1105.2, 1104.3, 1105.7, 1105.1, 1107.5, 1105.4, 1107.9, 1107.4, 1107.5, 1108.8, 1107, 1106.4, 1106.5, 1109.6, 1108.9, 1109.7, 1109.4, 1110.9, 1112.2, 1114.1, 1113.5, 1113.5, 1115.9, 1117.3, 1115.2, 1114.5, 1114.9, 1112.7, 1113.2, 1114.2, 1114.9, 1119.6, 1118.8, 1119.6, 1122.1, 1123.1, 1122.6, 1120.7, 1120.5, 1121.4, 1121.3, 1122, 1122.3, 1121, 1121.5, 1120.4, 1119, 1118.4, 1119.7, 1117.9, 1118.9, 1119.8, 1119.4, 1117.6, 1117.2, 1117.5, 1118.2, 1117.3, 1128.3, 1126.4, 1125.7, 1125.3, 1122.8, 1120.6, 1121, 1122.3, 1121.1, 1120.3, 1118, 1118.5, 1119.3, 1118.2, 1118.9, 1122.1, 1120.3, 1120.8, 1114, 1115.9, 1116.5, 1116.1, 1115.8, 1115.9, 1114.3, 1115.6, 1114.6, 1114.8, 1116.3, 1114.9, 1112.7, 1115.7, 1114.6, 1115.5, 1113.4, 1111.7, 1113.4, 1112.8, 1112.1, 1115.4, 1113.5, 1112.4, 1118, 1117, 1117.1, 1116.6, 1116.5, 1117.9, 1118.4, 1117.8, 1118.4, 1120.4, 1121.4, 1122.5, 1122.3, 1122.3, 1121.8, 1122.9, 1122, 1122, 1123, 1121.8, 1123.9, 1122.9, 1126.4, 1126.3, 1126.7, 1127.2, 1127.6, 1128.8, 1129.7, 1128.6, 1128.6, 1129.5, 1127.6, 1127.4, 1126.1, 1125.8, 1125.8, 1125.9, 1126.1, 1126.4, 1125.8, 1125.2, 1124.8, 1125.4, 1127.4, 1128.9, 1128.3, 1125, 1126.3, 1128, 1128.3, 1130.1, 1129.6, 1127.9, 1127.6, 1128.4, 1128.7, 1127.8, 1127.1, 1128.5, 1128.5, 1124.9, 1126.8, 1128.2, 1130.4, 1128.6, 1130.2, 1126.7, 1132.5, 1138.2, 1138.6, 1140, 1144.2, 1138.9, 1142.8, 1143, 1142.6, 1143.5, 1141.8, 1141.3, 1141.2, 1141.8, 1143.5, 1143.9, 1142.4, 1145.4, 1146.4, 1147.6, 1145.8, 1148.2, 1153.5, 1155.3, 1152.1, 1154.6, 1155.9, 1155.5, 1156.4, 1156.4, 1156, 1156, 1156.1, 1154.8, 1156.4, 1156.1, 1155.7, 1155.3, 1154.8, 1154.8, 1156.3, 1157.9, 1159.4, 1159.4, 1159, 1151.5, 1149.9, 1154, 1155.3, 1157.6, 1157.9, 1162.8, 1174.5, 1174.1, 1174.1, 1165.3, 1168.5, 1165.4, 1165.5, 1166.2, 1166.7, 1166.2, 1166.4, 1165.8, 1168.5, 1173.8, 1176.4, 1175.9, 1182.5, 1182.1, 1192.1, 1193.6, 1194.4, 1195.6, 1201, 1195.5, 1190.7, 1189.6, 1191.5,
1193.2, 1193.9, 1194, 1193.2, 1193.1, 1191.8, 1193.4, 1186.7, 1188.7, 1189.5, 1189.3, 1191.7, 1196.6, 1198.5, 1189.7, 1195.5, 1195.6, 1197.3, 1195.2, 1190.8, 1187.9, 1189.4, 1189.6, 1192.1, 1193.4, 1191.5, 1191.3, 1191.8, 1191.8, 1191.2, 1188, 1187, 1182.3, 1182.6, 1182.8, 1183.7, 1187.9, 1191, 1192.6, 1193.3, 1192.1, 1192.5, 1194, 1196.9, 1197.4, 1197.4, 1199, 1208.7, 1208.4, 1207, 1206.1, 1209.3, 1206.7, 1208.2, 1207.6, 1217.6, 1217.6, 1224.8, 1237.3, 1235.9, 1236, 1233, 1247.1, 1254.5, 1248.4, 1249.4, 1245, 1245.1, 1247, 1240.7, 1238.6, 1236.3, 1238.2, 1233.9, 1233.5, 1239.3, 1245, 1242.6, 1239.5, 1238.4, 1242.6, 1238, 1238.7, 1236, 1239.5, 1238.4, 1237.8, 1236.9, 1239.3, 1238.7, 1238.5, 1238.5, 1233.8, 1228.1, 1223.7, 1224.7, 1221, 1220.6, 1219.8, 1219.5, 1212.4, 1210.1, 1209.5, 1210.2, 1209.9, 1209.6, 1211.7, 1210, 1205.7, 1207.4, 1209.4, 1208.4, 1208.4, 1204.7, 1198.4, 1193.4, 1194.2, 1197.9, 1201.3, 1196.2, 1200, 1211, 1212, 1215.4, 1213.9, 1215.3, 1211.2, 1216.4, 1213, 1209.1, 1204.2, 1204.2, 1200.4, 1200.9, 1203.2, 1198.2, 1202.6, 1203.7, 1209.3, 1209.1, 1206.8, 1207.3, 1211.5, 1204.6, 1202.9, 1203, 1202.3, 1207, 1209.4, 1210.9, 1210.6, 1212.8, 1210.2, 1210.3, 1208.9, 1208.3, 1209, 1207.4, 1209.3, 1209.1, 1210.5, 1210.1, 1209.5, 1209.9, 1208.1, 1207.5, 1207.6, 1206.8, 1203.4, 1204.3, 1205.8, 1206.9, 1210.8, 1215.8, 1218.8, 1227.8, 1232.9, 1234.7, 1237.5, 1231.3, 1231.6, 1232.8, 1227.2, 1227.5, 1228.4, 1228, 1226.7, 1226.5, 1224.4, 1224.2, 1221.5, 1222.9, 1230.8, 1231.7, 1230.7, 1229.3, 1231.6, 1233, 1231.3, 1231.9, 1232.7, 1229.6, 1226.6, 1226.1, 1225.9, 1223.5, 1223.3, 1217.1, 1216.3, 1217, 1217.7, 1211, 1209.5, 1206.6, 1205.2, 1204, 1207.6, 1209.1, 1212.6, 1212.2, 1210.3, 1211.1, 1209.2, 1208.2, 1207.9, 1208.9, 1209.3, 1211.2, 1215.8, 1215.7, 1221.1, 1220.5, 1216.6, 1216.7, 1217.8, 1216.9, 1219.2, 1218.8, 1217.4, 1219.3, 1218.6, 1221.6, 1225.6, 1224.6, 1223.8, 1222.8, 1223.6, 1226.1, 1226, 1231.1, 1230, 1225.9, 1228, 1228.6, 1228.7, 1228.1, 1226, 1224.2, 1226.2, 1230.6, 1237.1, 1238, 1236.1, 1244.4, 1250.2, 1248.6, 1245.6, 1238.4, 1239.7, 1230.5, 1230.3, 1229.4, 1225, 1228.5, 1236.3, 1233.3, 1234.4, 1233.4, 1234.5, 1237.2, 1241, 1239.5, 1237.4, 1236, 1233.3, 1236.5, 1234.8, 1236.4, 1239.2, 1239.8, 1242.1, 1235.1, 1239.1, 1233.6, 1233.7, 1234.5, 1237.5, 1239, 1237.6, 1236.5, 1238.1, 1240, 1239.6, 1237, 1231.4, 1233.1, 1233.4, 1236.6, 1237.1, 1229.3, 1227.6, 1217.5, 1219.2, 1220.4, 1222.3, 1226.2, 1224.9, 1222.8, 1221.9, 1221.8, 1226.4, 1226.4, 1225.2, 1226.8, 1229, 1227.3, 1230.8, 1234.1, 1235.1, 1234.9, 1229.9, 1231.3, 1229.2, 1234.6, 1232.4, 1233.8, 1232.6, 1234.6, 1239.6, 1240.9, 1239.3, 1241.1, 1241.4, 1247.2, 1244.8, 1244.4, 1245.7),
.Dim = c(1000L, 1L), index = structure(c(1451386800, 1451390400, 1451394000, 1451397600, 1451401200, 1451404800, 1451408400, 1451412000, 1451415600, 1451419200, 1451422800, 1451430000, 1451433600, 1451437200, 1451440800, 1451444400, 1451448000, 1451451600, 1451455200, 1451458800, 1451462400, 1451466000, 1451469600, 1451473200, 1451476800, 1451480400, 1451484000, 1451487600, 1451491200, 1451494800, 1451498400, 1451502000, 1451505600, 1451509200, 1451516400, 1451520000, 1451523600, 1451527200, 1451530800, 1451534400, 1451538000, 1451541600, 1451545200, 1451548800, 1451552400, 1451556000, 1451559600, 1451563200, 1451566800, 1451570400, 1451574000, 1451577600, 1451581200, 1451584800, 1451588400, 1451592000, 1451595600, 1451862000, 1451865600, 1451869200, 1451872800, 1451876400, 1451880000, 1451883600, 1451887200, 1451890800, 1451894400, 1451898000, 1451901600, 1451905200, 1451908800, 1451912400, 1451916000, 1451919600, 1451923200, 1451926800, 1451930400, 1451934000, 1451937600, 1451941200, 1451948400, 1451952000, 1451955600, 1451959200, 1451962800, 1451966400, 1451970000, 1451973600, 1451977200, 1451980800, 1451984400, 1451988000, 1451991600, 1451995200, 1451998800, 1452002400, 1452006000, 1452009600, 1452013200, 1452016800, 1452020400, 1452024000, 1452027600, 1452034800, 1452038400, 1452042000, 1452045600, 1452049200, 1452052800, 1452056400, 1452060000, 1452063600, 1452067200, 1452070800, 1452074400, 1452078000, 1452081600, 1452085200, 1452088800, 1452092400, 1452096000, 1452099600, 1452103200, 1452106800, 1452110400, 1452114000, 1452121200, 1452124800, 1452128400, 1452132000, 1452135600, 1452139200, 1452142800, 1452146400, 1452150000, 1452153600, 1452157200, 1452160800, 1452164400, 1452168000, 1452171600, 1452175200, 1452178800, 1452182400, 1452186000, 1452189600, 1452193200, 1452196800, 1452200400, 1452207600, 1452211200, 1452214800, 1452218400, 1452222000, 1452225600, 1452229200, 1452232800, 1452236400, 1452240000, 1452243600, 1452247200, 1452250800, 1452254400, 1452258000, 1452261600, 1452265200, 1452268800, 1452272400, 1452276000, 1452279600, 1452283200, 1452286800, 1452466800, 1452470400, 1452474000, 1452477600, 1452481200, 1452484800, 1452488400, 1452492000, 1452495600, 1452499200, 1452502800, 1452506400, 1452510000, 1452513600, 1452517200, 1452520800, 1452524400, 1452528000, 1452531600, 1452535200, 1452538800, 1452542400, 1452546000, 1452553200, 1452556800, 1452560400, 1452564000, 1452567600, 1452571200, 1452574800, 1452578400, 1452582000, 1452585600, 1452589200, 1452592800, 1452596400, 1452600000, 1452603600, 1452607200, 1452610800, 1452614400, 1452618000, 1452621600, 1452625200, 1452628800, 1452632400, 1452639600, 1452643200, 1452646800, 1452650400, 1452654000, 1452657600, 1452661200, 1452664800, 1452668400, 1452672000, 1452675600, 1452679200, 1452682800, 1452686400, 1452690000, 1452693600, 1452697200, 1452700800, 1452704400, 1452708000, 1452711600, 1452715200, 1452718800, 1452726000, 1452729600, 1452733200, 1452736800, 1452740400, 1452744000, 1452747600, 1452751200, 1452754800, 1452758400, 1452762000, 1452765600, 1452769200, 1452772800, 1452776400, 1452780000, 1452783600, 1452787200, 1452790800, 1452794400, 1452798000, 1452801600, 1452805200, 1452812400, 1452816000, 1452819600, 1452823200, 1452826800, 1452830400, 1452834000, 1452837600, 1452841200, 1452844800, 1452848400, 1452852000, 1452855600, 1452859200, 1452862800, 1452866400, 1452870000, 1452873600, 1452877200, 1452880800, 1452884400, 1452888000, 1452891600, 1453071600, 1453075200, 1453078800, 1453082400, 1453086000, 1453089600, 1453093200, 1453096800, 1453100400, 1453104000, 1453107600, 1453111200, 1453114800, 1453118400, 1453122000, 1453125600, 1453129200, 1453132800, 1453136400, 1453158000, 1453161600, 1453165200, 1453168800, 1453172400, 1453176000, 1453179600, 1453183200, 1453186800, 1453190400, 1453194000, 1453197600, 1453201200, 1453204800, 1453208400, 1453212000, 1453215600, 1453219200, 1453222800,
1453226400, 1453230000, 1453233600, 1453237200, 1453244400, 1453248000, 1453251600, 1453255200, 1453258800, 1453262400, 1453266000, 1453269600, 1453273200, 1453276800, 1453280400, 1453284000, 1453287600, 1453291200, 1453294800, 1453298400, 1453302000, 1453305600, 1453309200, 1453312800, 1453316400, 1453320000, 1453323600, 1453330800, 1453334400, 1453338000, 1453341600, 1453345200, 1453348800, 1453352400, 1453356000, 1453359600, 1453363200, 1453366800, 1453370400, 1453374000, 1453377600, 1453381200, 1453384800, 1453388400, 1453392000, 1453395600, 1453399200, 1453402800, 1453406400, 1453410000, 1453417200, 1453420800, 1453424400, 1453428000, 1453431600, 1453435200, 1453438800, 1453442400, 1453446000, 1453449600, 1453453200, 1453456800, 1453460400, 1453464000, 1453467600, 1453471200, 1453474800, 1453478400, 1453482000, 1453485600, 1453489200, 1453492800, 1453496400, 1453676400, 1453680000, 1453683600, 1453687200, 1453690800, 1453694400, 1453698000, 1453701600, 1453705200, 1453708800, 1453712400, 1453716000, 1453719600, 1453723200, 1453726800, 1453730400, 1453734000, 1453737600, 1453741200, 1453744800, 1453748400, 1453752000, 1453755600, 1453762800, 1453766400, 1453770000, 1453773600, 1453777200, 1453780800, 1453784400, 1453788000, 1453791600, 1453795200, 1453798800, 1453802400, 1453806000, 1453809600, 1453813200, 1453816800, 1453820400, 1453824000, 1453827600, 1453831200, 1453834800, 1453838400, 1453842000, 1453849200, 1453852800, 1453856400, 1453860000, 1453863600, 1453867200, 1453870800, 1453874400, 1453878000, 1453881600, 1453885200, 1453888800, 1453892400, 1453896000, 1453899600, 1453903200, 1453906800, 1453910400, 1453914000, 1453917600, 1453921200, 1453924800, 1453928400, 1453935600, 1453939200, 1453942800, 1453946400, 1453950000, 1453953600, 1453957200, 1453960800, 1453964400, 1453968000, 1453971600, 1453975200, 1453978800, 1453982400, 1453986000, 1453989600, 1453993200, 1453996800, 1454000400, 1454004000, 1454007600, 1454011200, 1454014800, 1454022000, 1454025600, 1454029200, 1454032800, 1454036400, 1454040000, 1454043600, 1454047200, 1454050800, 1454054400, 1454058000, 1454061600, 1454065200, 1454068800, 1454072400, 1454076000, 1454079600, 1454083200, 1454086800, 1454090400, 1454094000, 1454097600, 1454101200, 1454281200, 1454284800, 1454288400, 1454292000, 1454295600, 1454299200, 1454302800, 1454306400, 1454310000, 1454313600, 1454317200, 1454320800, 1454324400, 1454328000, 1454331600, 1454335200, 1454338800, 1454342400, 1454346000, 1454349600, 1454353200, 1454356800, 1454360400, 1454367600, 1454371200, 1454374800, 1454378400, 1454382000, 1454385600, 1454389200, 1454392800, 1454396400, 1454400000, 1454403600, 1454407200, 1454410800, 1454414400, 1454418000, 1454421600, 1454425200, 1454428800, 1454432400, 1454436000, 1454439600, 1454443200, 1454446800, 1454454000, 1454457600, 1454461200, 1454464800, 1454468400, 1454472000, 1454475600, 1454479200, 1454482800, 1454486400, 1454490000, 1454493600, 1454497200, 1454500800, 1454504400, 1454508000, 1454511600, 1454515200, 1454518800, 1454522400, 1454526000, 1454529600, 1454533200, 1454540400, 1454544000, 1454547600, 1454551200, 1454554800, 1454558400, 1454562000, 1454565600, 1454569200, 1454572800, 1454576400, 1454580000, 1454583600, 1454587200, 1454590800, 1454594400, 1454598000, 1454601600, 1454605200, 1454608800, 1454612400, 1454616000, 1454619600, 1454626800, 1454630400, 1454634000, 1454637600, 1454641200, 1454644800, 1454648400, 1454652000,
1454655600, 1454659200, 1454662800, 1454666400, 1454670000, 1454673600, 1454677200, 1454680800, 1454684400, 1454688000, 1454691600, 1454695200, 1454698800, 1454702400, 1454706000, 1454709600, 1454886000, 1454889600, 1454893200, 1454896800, 1454900400, 1454904000, 1454907600, 1454911200, 1454914800, 1454918400, 1454922000, 1454925600, 1454929200, 1454932800, 1454936400, 1454940000, 1454943600, 1454947200, 1454950800, 1454954400, 1454958000, 1454961600, 1454965200, 1454972400, 1454976000, 1454979600, 1454983200, 1454986800, 1454990400, 1454994000, 1454997600, 1455001200, 1455004800, 1455008400, 1455012000, 1455015600, 1455019200, 1455022800, 1455026400, 1455030000, 1455033600, 1455037200, 1455040800, 1455044400, 1455048000, 1455051600, 1455058800, 1455062400, 1455066000, 1455069600, 1455073200, 1455076800, 1455080400, 1455084000, 1455087600, 1455091200, 1455094800, 1455098400, 1455102000, 1455105600, 1455109200, 1455112800, 1455116400, 1455120000, 1455123600, 1455127200, 1455130800, 1455134400, 1455138000, 1455141600, 1455145200, 1455148800, 1455152400, 1455156000,
1455159600, 1455163200, 1455166800, 1455170400, 1455174000, 1455177600, 1455181200, 1455184800, 1455188400, 1455192000, 1455195600, 1455199200, 1455202800, 1455206400, 1455210000, 1455213600, 1455217200, 1455220800, 1455224400, 1455231600, 1455235200, 1455238800, 1455242400, 1455246000, 1455249600, 1455253200, 1455256800, 1455260400, 1455264000, 1455267600, 1455271200, 1455274800, 1455278400, 1455282000, 1455285600, 1455289200, 1455292800, 1455296400, 1455300000, 1455303600, 1455307200, 1455310800, 1455490800, 1455494400, 1455498000, 1455501600, 1455505200, 1455508800, 1455512400, 1455516000, 1455519600, 1455523200, 1455526800, 1455530400, 1455534000, 1455537600, 1455541200, 1455544800, 1455548400, 1455552000, 1455555600, 1455577200, 1455580800, 1455584400, 1455588000, 1455591600, 1455595200, 1455598800, 1455602400, 1455606000, 1455609600, 1455613200, 1455616800, 1455620400, 1455624000, 1455627600, 1455631200, 1455634800, 1455638400, 1455642000, 1455645600, 1455649200, 1455652800, 1455656400, 1455663600, 1455667200, 1455670800, 1455674400, 1455678000, 1455681600, 1455685200, 1455688800, 1455692400, 1455696000, 1455699600, 1455703200, 1455706800, 1455710400, 1455714000, 1455717600, 1455721200, 1455724800, 1455728400, 1455732000, 1455735600, 1455739200, 1455742800, 1455750000, 1455753600, 1455757200, 1455760800, 1455764400, 1455768000, 1455771600, 1455775200, 1455778800, 1455782400, 1455786000, 1455789600, 1455793200, 1455796800, 1455800400, 1455804000, 1455807600, 1455811200, 1455814800, 1455818400, 1455822000, 1455825600, 1455829200, 1455836400, 1455840000, 1455843600, 1455847200, 1455850800, 1455854400, 1455858000, 1455861600, 1455865200, 1455868800, 1455872400, 1455876000, 1455879600, 1455883200, 1455886800, 1455890400, 1455894000, 1455897600, 1455901200, 1455904800, 1455908400, 1455912000, 1455915600, 1456095600, 1456099200, 1456102800, 1456106400, 1456110000, 1456113600, 1456117200, 1456120800, 1456124400, 1456128000, 1456131600, 1456135200, 1456138800, 1456142400, 1456146000, 1456149600, 1456153200, 1456156800, 1456160400, 1456164000, 1456167600, 1456171200, 1456174800, 1456182000, 1456185600, 1456189200, 1456192800, 1456196400, 1456200000, 1456203600, 1456207200, 1456210800, 1456214400, 1456218000, 1456221600, 1456225200, 1456228800, 1456232400, 1456236000, 1456239600, 1456243200, 1456246800, 1456250400, 1456254000, 1456257600, 1456261200, 1456268400, 1456272000, 1456275600, 1456279200, 1456282800, 1456286400, 1456290000, 1456293600, 1456297200, 1456300800, 1456304400, 1456308000, 1456311600, 1456315200, 1456318800, 1456322400, 1456326000, 1456329600, 1456333200, 1456336800, 1456340400, 1456344000, 1456347600, 1456354800, 1456358400, 1456362000, 1456365600, 1456369200, 1456372800, 1456376400, 1456380000, 1456383600, 1456387200, 1456390800, 1456394400, 1456398000, 1456401600, 1456405200, 1456408800, 1456412400, 1456416000, 1456419600, 1456423200, 1456426800, 1456430400, 1456434000, 1456441200, 1456444800, 1456448400, 1456452000, 1456455600, 1456459200, 1456462800, 1456466400, 1456470000, 1456473600, 1456477200, 1456480800, 1456484400, 1456488000, 1456491600, 1456495200, 1456498800, 1456502400, 1456506000, 1456509600, 1456513200, 1456516800, 1456520400, 1456700400, 1456704000, 1456707600, 1456711200, 1456714800, 1456718400, 1456722000, 1456725600, 1456729200, 1456732800, 1456736400, 1456740000, 1456743600, 1456747200, 1456750800, 1456754400, 1456758000, 1456761600, 1456765200, 1456768800, 1456772400, 1456776000, 1456779600, 1456786800, 1456790400, 1456794000, 1456797600, 1456801200, 1456804800),
tzone = "", tclass = c("POSIXlt","POSIXt")), class = c("xts", "zoo"), .indexCLASS = c("POSIXlt", "POSIXt"), tclass = c("POSIXlt", "POSIXt"), .indexTZ = "", tzone = "", .CLASS = "double")
#THESE WORK AS INTENDED
SelectedDates <- DATSxts['2015-12-30::2015-12-31'] #get data between those dates
SelectedMonth <- DATSxts[.indexmon(DATSxts)==1] #get data for months February
SelectedDayYr <- DATSxts[.indexyday(DATSxts)==5] #get data for 5th trading days of the year
SelectedDayMon <- DATSxts[.indexmday(DATSxts)==10] #get data for 10th day of every month
SelectedDayWk <- DATSxts[.indexwday(DATSxts)==1] #get data for mondays
SelectedHour <- DATSxts[.indexhour(DATSxts)==08] #get data for 8AM
#THESE DO NOT WORK
SelectedYear <- DATSxts[.indexyear(DATSxts)==2016] #get data for year 2016
SelectedWeek <- DATSxts[.indexweek(DATSxts)==1] #get data for weeks 1
SelectedDay <- DATSxts[.indexday(DATSxts)==10] #get data for days 10
SelectedMin <- DATSxts[.indexmin(DATSxts)==30] #get data for every minute 30
****(Note: for some odd reason if I put all data/xts code in less than 8 lines loading the data gives an error message)****
You need to look at what .indexyear actually returns:
> .indexyear(DATSxts[1,])
[1] 115
> length( DATSxts[.indexyear(DATSxts)==116] )
[1] 943
> head( DATSxts[.indexyear(DATSxts)==116] )
[,1]
2016-01-03 15:00:00 1063.1
2016-01-03 16:00:00 1064.6
2016-01-03 17:00:00 1063.5
2016-01-03 18:00:00 1064.3
2016-01-03 19:00:00 1063.7
2016-01-03 20:00:00 1065.3
The 1900 basis is probably a holdover from an effort to emulate Excel on Windows. The weeks and days values are also different than you apparently expected:
> table( .indexweek(DATSxts) )
2400 2401 2402 2403 2404 2405 2406 2407 2408 2409
58 115 115 111 115 116 116 111 115 28
> table( .indexday(DATSxts) )
16798 16799 16800 16803 16804 16805 16806 16807 16808 16810 16811 16812 16813 16814
12 23 22 1 23 23 23 23 22 1 23 23 23 23
16815 16817 16818 16819 16820 16821 16822 16824 16825 16826 16827 16828 16829 16831
22 1 19 23 23 23 22 1 23 23 23 23 22 1
16832 16833 16834 16835 16836 16838 16839 16840 16841 16842 16843 16845 16846 16847
23 23 23 23 23 1 23 23 24 23 22 1 19 23
16848 16849 16850 16852 16853 16854 16855 16856 16857 16859 16860 16861
23 23 22 1 23 23 23 23 22 1 23 5
Granted, these aren't well-documented, but there are .index* functions that do what you want. A quick look at the source of a couple of the functions could have pointed you in the right direction. Take .indexyear for example, and note that ?POSIXlt says year is years since 1900.
R> .indexyear
function (x)
{
as.POSIXlt(.POSIXct(.index(x)))$year
}
<environment: namespace:xts>
SelectedYear <- DATSxts[(1900+.indexyear(DATSxts))==2016] #data for year 2016
Week of the year is not simple, and looking at the source would not have likely helped... There are several different ways to count the weeks in a year. See the "%U", "%V", and "%W" formats in ?strftime.
SelectedWeek <- DATSxts[strftime(index(DATSxts),"%W")=="00"] #get data for weeks 1
.indexday returns the day/date of the underlying index. Use .indexmday if you want the day of the month.
SelectedDay <- DATSxts[.indexmday(DATSxts)==10] #get data for days 10
I'm not sure what you expect .indexmin to do, since you do not have any data that occur on the 30th minute of any hour. The function below seems to be working as expected.
SelectedMin <- DATSxts[.indexmin(DATSxts)==30] #get data for every minute 30