将数据[公历]与具有360天日历的数据合并

问题描述 投票:0回答:2

我有以下问题。基本上我有遵循公历的数据和遵循 360 天日历和 365 天日历(无闰年)的数据。它是提供数据的模型的一个功能。我只能在库(PCICt)的帮助下为具有 360 或 365 天日历的数据创建时间索引,因此时间索引属于 PCICt 类,而不是那些具有 360 天或 365 天日历的数据集的日期类。

我成功地轻松更改了 365 天日历的数据时间索引的类别,因为它总是错过 2 月 29 日。总的来说,它的天数比公历数据少,这就是以下代码有效的原因:

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))

我可以使用以下代码将公历数据与 365 天日历数据(Modellwind.IPSL.1971_2100.mat.5.zoo 有 360 天日历)合并:

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.

问题是,360 天的日历每月有 30 天。因为2月30日不存在,所以我无法使用上面的方法。是否可以使用公历数据集的索引来掩盖 360 天日历数据中的日期,而公历数据中不存在这些日期?在 360 天日历的数据中,我会在每个月的 31 日有 NA,该日历有 31 天,并且 2 月 30 日将始终被排除/“删除”。

所有这 2 种日历类型的 1972 年数据示例。 1972 年是闰年。

公历数据:

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")

360天日历数据:

   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")
r indexing calendar time-series zoo
2个回答
1
投票

我不熟悉360天日历,但360天日历的索引似乎是纪元秒,起源于公历1970-01-01。如果是这种情况,此代码将起作用。

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)

请确保检查 360 天向量索引中的第二个纪元的起源为 1970-01-01。


0
投票

您显然正在使用来自三个不同模型的气候预测数据,每个模型使用不同的日历。正如您所说,这些日历是各个型号的功能,您应该尊重该功能。然后,该方法是不是合并原始数据然后进行分析,而是相反:首先分别分析每个模型,这通常涉及将每日数据聚合到每月数据,然后计算异常(即2081 - 2100 年期间 X 月的平均值与基线期间(例如 1971 - 2000 年)的同月平均值相比如何),然后finally 将各个模型的这些结果合并为最终结果(例如多模型集成)。

使用 CFtime 包(诚然,2017 年还没有),使用气候预测模型使用的不同日历变得轻而易举:

install.packages("CFtime")
library(CFtime)
library(ncdf4)

# Open the climate projection model
nc <- nc_open("./my_model.nc")

# Build the time series from the information in the data file
# No need to worry about the details of the calendar, the CFtime package manages
cf <- CFtime(nc$dim$time$units, nc$dim$time$calendar, nc$dim$time$vals)

# Read the data from the file
modellwind <- ncvar_get(nc, "var")

# Build a factor, as needed
fac <- CFfactor(cf, "month")

# Apply your function using the factor
res <- aperm(apply(modellwind, 1:2, tapply, fac, fun), c(2, 3, 1))

对其他型号重复此操作。现在,您可以合并不同模型的结果,假设您的

fun
操作中存在某种形式的聚合(例如从每日到每月,如上例所示)。这与每个型号的特定日历无关。

© www.soinside.com 2019 - 2024. All rights reserved.