检查数据集中不存在的一年的日期

时间:2017-06-25 14:44:05

标签: r date lubridate

在R中执行此操作,

我有一组361个观测值,"数据集",2列:日期和一些数字。所有日期均为2015-01-01至2015-12-31。显然有4天不存在,我想知道哪些。

我试着这样做:

MA <- rep(NA, 365)
 for(i in 2:365){
  MA[1] <- as.Date("2015-01-01")
  MA[i] <- MA[i-1] + days(1)
 }
MA[!(%in% Dataset$Date)]

但不起作用......矢量MA由数字16436的365倍组成 有什么解决方案吗?

编辑: 我设置上面称为数据集:

  

dput(AW1)

structure(list(Date = structure(c(1420070400, 1420243200, 1420329600, 
1420416000, 1420502400, 1420588800, 1420675200, 1420761600, 1420848000, 
1420934400, 1421020800, 1421107200, 1421193600, 1421280000, 1421366400, 
1421452800, 1421539200, 1421625600, 1421712000, 1421798400, 1421884800, 
1421971200, 1422057600, 1422144000, 1422230400, 1422316800, 1422403200, 
1422489600, 1422576000, 1422662400, 1422748800, 1422835200, 1422921600, 
1423008000, 1423094400, 1423180800, 1423267200, 1423353600, 1423440000, 
1423526400, 1423612800, 1423699200, 1423785600, 1423872000, 1423958400, 
1424044800, 1424131200, 1424217600, 1424304000, 1424390400, 1424476800, 
1424563200, 1424649600, 1424736000, 1424822400, 1424908800, 1424995200, 
1425081600, 1425168000, 1425254400, 1425340800, 1425427200, 1425513600, 
1425600000, 1425686400, 1425772800, 1425859200, 1425945600, 1426032000, 
1426118400, 1426204800, 1426291200, 1426377600, 1426464000, 1426550400, 
1426636800, 1426723200, 1426809600, 1426896000, 1426982400, 1427068800, 
1427155200, 1427241600, 1427328000, 1427414400, 1427500800, 1427587200, 
1427673600, 1427760000, 1427846400, 1427932800, 1428019200, 1428105600, 
1428192000, 1428278400, 1428364800, 1428451200, 1428537600, 1428624000, 
1428710400, 1428796800, 1428883200, 1428969600, 1429056000, 1429142400, 
1429228800, 1429315200, 1429401600, 1429488000, 1429574400, 1429660800, 
1429747200, 1429833600, 1429920000, 1430006400, 1430092800, 1430179200, 
1430265600, 1430352000, 1430438400, 1430524800, 1430611200, 1430697600, 
1430784000, 1430870400, 1430956800, 1431043200, 1431129600, 1431216000, 
1431302400, 1431388800, 1431475200, 1431561600, 1431734400, 1431820800, 
1431907200, 1431993600, 1432080000, 1432166400, 1432252800, 1432339200, 
1432425600, 1432512000, 1432598400, 1432684800, 1432771200, 1432857600, 
1432944000, 1433030400, 1433116800, 1433203200, 1433289600, 1433376000, 
1433462400, 1433548800, 1433635200, 1433721600, 1433808000, 1433894400, 
1433980800, 1434067200, 1434153600, 1434240000, 1434326400, 1434412800, 
1434499200, 1434585600, 1434672000, 1434758400, 1434844800, 1434931200, 
1435017600, 1435104000, 1435190400, 1435276800, 1435363200, 1435449600, 
1435536000, 1435622400, 1435708800, 1435795200, 1435881600, 1435968000, 
1436054400, 1436140800, 1436227200, 1436313600, 1436400000, 1436486400, 
1436572800, 1436659200, 1436745600, 1436832000, 1436918400, 1437004800, 
1437091200, 1437177600, 1437264000, 1437350400, 1437436800, 1437523200, 
1437609600, 1437696000, 1437782400, 1437868800, 1437955200, 1438041600, 
1438128000, 1438214400, 1438300800, 1438387200, 1438473600, 1438560000, 
1438646400, 1438732800, 1438819200, 1438905600, 1438992000, 1439078400, 
1439164800, 1439251200, 1439337600, 1439424000, 1439510400, 1439596800, 
1439683200, 1439769600, 1439856000, 1439942400, 1440028800, 1440115200, 
1440201600, 1440288000, 1440374400, 1440460800, 1440547200, 1440633600, 
1440720000, 1440806400, 1440892800, 1440979200, 1441065600, 1441152000, 
1441238400, 1441324800, 1441411200, 1441497600, 1441584000, 1441670400, 
1441756800, 1441843200, 1441929600, 1442016000, 1442102400, 1442188800, 
1442275200, 1442361600, 1442448000, 1442534400, 1442620800, 1442707200, 
1442793600, 1442880000, 1442966400, 1443052800, 1443139200, 1443225600, 
1443312000, 1443398400, 1443484800, 1443571200, 1443657600, 1443744000, 
1443830400, 1443916800, 1444003200, 1444089600, 1444176000, 1444262400, 
1444348800, 1444435200, 1444521600, 1444608000, 1444694400, 1444780800, 
1444867200, 1444953600, 1445040000, 1445126400, 1445212800, 1445299200, 
1445385600, 1445472000, 1445558400, 1445644800, 1445731200, 1445817600, 
1445904000, 1445990400, 1446076800, 1446163200, 1446249600, 1446336000, 
1446422400, 1446508800, 1446595200, 1446681600, 1446768000, 1446854400, 
1446940800, 1447027200, 1447113600, 1447200000, 1447286400, 1447372800, 
1447459200, 1447545600, 1447632000, 1447718400, 1447804800, 1447891200, 
1447977600, 1448064000, 1448150400, 1448236800, 1448323200, 1448409600, 
1448496000, 1448582400, 1448668800, 1448755200, 1448841600, 1448928000, 
1449014400, 1449100800, 1449187200, 1449273600, 1449360000, 1449446400, 
1449532800, 1449619200, 1449705600, 1449792000, 1449878400, 1449964800, 
1450051200, 1450137600, 1450224000, 1450310400, 1450396800, 1450483200, 
1450569600, 1450656000, 1450742400, 1450828800, 1450915200, 1451001600, 
1451174400, 1451260800, 1451347200, 1451433600), class = c("POSIXct", 
"POSIXt"), tzone = "UTC"), Volume = c(2224.5, 44.3, 1835.4, 22205.2, 
1100.9, 1409.7, 4233.9, 1857.5, 0.5, 1378.6, 1917.7, 4438.1, 
73314, 1929.7, 666.9, 26.4, 1331.7, 7182.9, 2902.4, 22501.5, 
2632.9, 1301.7, 102, 3673.7, 3446.7, 24917.2, 3867.7, 3977.5, 
1780.7, 13.2, 2762.6, 5084.2, 3071.9, 4674, 4061.2, 2567.3, 216.5, 
3323.7, 16072.4, 2108.4, 2786.2, 2883.9, 1848, 50.2, 2884.5, 
9099.1, 4772.4, 2814.2, 2507.8, 1532.9, 2, 2932.5, 5734.1, 3077.1, 
4960.5, 4289.3, 39098.7, 42.7, 1688.5, 3714.8, 6161.5, 4288.6, 
25189, 2376.3, 18.4, 2530.1, 28803.4, 4369.3, 7202.6, 3500.1, 
1880.4, 1705.5, 1541.4, 10804.1, 3712.7, 3182.5, 3527.6, 2266.8, 
123.5, 2721.4, 5698, 8242.8, 4526.2, 13216.9, 1666.8, 61.8, 1596.4, 
3999, 2026.6, 8054.1, 7198.6, 1754.9, 9.7, 44.4, 2837.6, 3479.5, 
5583.3, 2247.9, 11005.5, 112, 614.1, 3668.8, 2464.6, 2156.6, 
2086, 854.2, 90.1, 673.2, 18881.6, 2561.1, 11970.8, 2405.9, 1322.4, 
226.2, 900.7, 1119.4, 3307.2, 10196, 2721.7, 27680.5, 7.4, 1130.1, 
5506.6, 4332.5, 4490, 3839.1, 3902.9, 160.1, 1335.7, 13019.7, 
1928.8, 2770.7, 58916.9, 200.6, 1759.9, 5744.1, 4217.8, 1734.2, 
2385.6, 2810.8, 2409.8, 616.3, 2927.8, 1196.8, 4121.3, 18369.2, 
2028, 3970, 1653.5, 8414.8, 3273.6, 2806.7, 3887.8, 1921, 3088.3, 
1969.7, 1570.6, 3932.8, 16083.7, 4239.9, 2512.2, 2256.3, 618.8, 
2312.8, 3129.2, 2973.7, 3311, 1889.8, 4972.5, 1871.8, 1480.9, 
3875.4, 2899.1, 3199.6, 1227.6, 22825.8, 1704.6, 2799.4, 2039.6, 
1579.7, 4847.7, 1284.8, 68.7, 1506.6, 18901.3, 13065.2, 30693.9, 
4664.7, 4345, 11.6, 519.9, 2128.6, 4278.8, 2287.6, 2350.6, 577.7, 
5.5, 987.8, 11598.7, 3479.5, 195.2, 5739.5, 2712.7, 45.6, 209.2, 
5504.3, 2638.1, 1502.4, 2591.6, 983.5, 47.2, 556.9, 6807.1, 3577.6, 
1790.5, 3795.6, 2223.6, 37.7, 599.7, 3029.7, 3722.8, 3904.5, 
3650.1, 1190.3, 100.6, 605.9, 2981.2, 2090.1, 1876.7, 2296.2, 
1013.7, 49.8, 421.3, 3973.4, 3028.6, 2808.4, 3595.6, 1450, 43.4, 
914.4, 4933.7, 3790.2, 1735.5, 2675.1, 1211.9, 48, 1134.9, 3888.2, 
5568.9, 3657.6, 7268.8, 2565.8, 44.1, 509.6, 56995.8, 2383.3, 
1789.9, 4338.9, 2458.1, 63.4, 1073.7, 4398.2, 3822.8, 879, 2079, 
2036.6, 216.6, 633.8, 9265.2, 1682.8, 1500.9, 3907.3, 2813.5, 
17, 4582.7, 9989.6, 3588.3, 5064.6, 97352.7, 1892.3, 54, 1141.1, 
10532.7, 9683, 19452.3, 4151.3, 2243, 33.7, 2208.9, 6159.6, 5811.6, 
54718, 4610.5, 3598.8, 167.3, 8045.6, 6464.1, 3895.1, 3857.8, 
4043.6, 2080.8, 350.4, 16011.2, 7012.4, 4329.9, 4554.6, 7454.4, 
4379, 49.9, 2446.7, 32326.9, 28430.4, 11898.1, 11953.9, 3514.7, 
74.3, 7928.2, 2188.7, 1895.9, 2113.7, 4400.2, 2367, 10, 2460, 
2607.7, 14809.5, 2594.6, 2670.7, 3387.4, 26.2, 2321.6, 2555.1, 
2302, 17930.3, 5320.1, 1865.2, 69, 3560.6, 1396.6, 3248, 2639.1, 
4639.1, 327.2, 177.8, 3518.4, 3120.7, 4778.8, 4848.4, 2806.6, 
3855.5, 1.7, 4524.5, 2473.7, 4024.4, 2574.3, 1350.6, 2.9, 703.1, 
940.7, 9048.1, 164.2)), .Names = c("Date", "Volume"), row.names = c(NA, 
-361L), class = "data.frame")

0 个答案:

没有答案