解决.csv文件中的NA值

时间:2018-05-18 11:55:58

标签: r csv time-series estimation

我正在处理4个不同的时间序列,但由于所有时间序列都有不同的开始和结束日期,因此有一些“NA”值。为了解决这个问题,我想在开头和结尾删除一些值,以便所有变量以相同的观察量结束。

我的问题是:如何实现这一目标?我已经读过,在数据准备中,最好在zoo而不是ts环境中工作。尽管如此,数据已在ts环境中准备好,并已保存为.csv文件。

我阅读数据的标准方式:

ger.data <- read.table("inputData/rstar.data.ger.csv",
                  sep = ',', na.strings = ".", header=TRUE, stringsAsFactors=FALSE)

数据:

dput(ger.data)
structure(list(gdp.log = c(NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, 12.8840503491576, 12.8869726344706, 12.9204968561163, 
12.9438274460798, 12.9508226975537, 12.9598326831315, 12.9699252303554, 
12.9712706838341, 12.9832208431563, 12.9934043726069, 12.9994338713584, 
13.0182776044722, 13.0243844396313, 13.035927107736, 13.0540973845342, 
13.053452645401, 13.0710890302057, 13.0786225438817, 13.0798900201348, 
13.0688845385587, 13.0832129017843, 13.0910336880674, 13.0984128394085, 
13.0926667656675, 13.1055915127038, 13.1105701093852, 13.119314735013, 
13.1262159467198, 13.1287012505881, 13.1327829050981, 13.1345626626113, 
13.1421052185393, 13.1455993198096, 13.1555795609356, 13.1649649076113, 
13.173060293994, 13.1804681211107, 13.1817750285751, 13.1809209231138, 
13.2039931327435, 13.2072154247188, 13.2100738433077, 13.2176681026483, 
13.2173316805937, 13.2177517359708, 13.2291277072538, 13.2297404584268, 
13.2215062032288, 13.2221345014757, 13.2340192357447, 13.2355509813313, 
13.2409585276508, 13.2484725433257, 13.2479082122106, 13.2471370327532, 
13.2498925426482, 13.257285802095, 13.2671647742844, 13.2697897856204, 
13.2792525897404, 13.2981972680627, 13.3086022514823, 13.3222104610641, 
13.3374408854799, 13.3480716370407, 13.359023171372, 13.3637051323603, 
13.3742094421193, 13.3745032426961, 13.3710561499247, 13.3543334600286, 
13.3168292261946, 13.3213404576914, 13.3323989938769, 13.3441283789553, 
13.3505454142055, 13.3703322154341, 13.3834067699044, 13.3949886632219, 
13.4133150987237, 13.4177695421018, 13.4269276403545, 13.430715348023, 
13.4371055017517, 13.4411021588013, 13.4493897130691, 13.449440186328, 
13.4527356182524, 13.4658424373757, 13.4760845632917, 13.4841231715523, 
13.4975575764497, 13.5007587163897, 13.5076829194195, 13.5202706636591, 
13.5285828675615, 13.5387235844532, 13.5446488926295, 13.5534338521478, 
13.5633204606829, 13.570039594766, 13.5752742543238, 13.5834486056741, 
13.5936649140038, 13.6081837597166, 13.6218918277317, 13.6285783886126, 
NA, NA), inflation = c(2.22222222222224, 1.244019138756, 0.75973409306742, 
1.80608365019013, 1.98487712665404, 2.64650283553874, 2.73327049952876, 
3.36134453781511, 3.15106580166824, 2.39410681399631, 2.47706422018348, 
3.25203252032522, 2.87511230907457, 2.42805755395685, 3.31244404655327, 
2.27471566054242, 2.09606986899562, 2.72168568920105, 2.2530329289428, 
2.05303678357573, 3.07955517536358, 3.84615384615386, 3.98305084745763, 
4.10729253981556, 4.06639004149377, 3.04526748971191, 2.93398533007336, 
2.49597423510466, 1.8341307814992, 1.75718849840257, 1.10847189231985, 
1.49253731343286, 1.25293657008615, 1.33437990580847, 1.80109631949884, 
1.62538699690402, 2.01082753286931, 2.09140201394268, 1.92307692307691, 
2.89413556740292, 3.33586050037907, 3.5660091047041, 4.00000000000001, 
4.44115470022204, 5.06236243580337, 5.78754578754579, 5.66037735849054, 
5.31537916371368, 4.88826815642457, 5.47091412742381, 6.25000000000001, 
6.46029609690444, 7.39014647137152, 6.9599474720946, 7.30446024563674, 
7.45891276864728, 7.06757594544325, 6.99815837937383, 6.44578313253009, 
5.88235294117648, 6.25361899247252, 6.08146873207113, 5.43293718166383, 
5.22222222222223, 4.30517711171662, 3.78583017847487, 3.70370370370372, 
3.80147835269271, 3.81400208986417, 3.85617509119333, 3.46790890269152, 
3.00101729399797, 2.86864620030195, 2.50878073256398, 2.50125062531265, 
2.91358024691356, 3.27788649706457, 4.650024473813, 5.31966813079548, 
5.51823416506719, 5.92136428233066, 5.19176800748362, 5.14365152919371, 
5.72987721691677, 5.81395348837209, 6.66963094708762, 7.13970912296167, 
5.89247311827958, 5.36770921386304, 5.08545227177989, 4.648292883587, 
4.06173842404549, 3.28920978740473, 3.13367711225704, 2.71226415094341, 
2.84933645589384, 2.83495145631071, 1.88461538461538, 2.06659012629162, 
2.31499051233397, 2.30362537764349, 2.076255190638, 1.57480314960629, 
0.741839762611279, 0, -0.332840236686399, -0.922849760059066, 
-0.515463917525782, 0.0369139904023732, 0.519480519480511, 0.968703427719836, 
0.962250185048109, 1.14391143911439, 1.29198966408267, 1.69741697416972, 
2.4193548387097, 2.88215979569498, 2.80612244897959, 3.01161103047896, 
2.72011453113812, 2.3049645390071, 2.72952853598016, 3.02923564635434, 
2.84251480582282, 3.29915972330998, 4.51351791825871, 5.50437317784258, 
5.9108527131783, 6.09404990403073, 4.95750708215298, 3.33642261353105, 
4.66605672461115, 4.38715513342377, 4.5434098065677, 4.30493273542601, 
2.97202797202796, 2.77296360485268, 2.58175559380379, 2.45055889939811, 
2.07979626485568, 1.7284991568297, 1.5520134228188, 1.46873688627781, 
1.45530145530146, 1.45047658516367, 1.36307311028499, 1.53019023986766, 
1.76229508196721, 1.55228758169937, 2.32273838630808, 2.11812627291242, 
1.24848973016513, 1.36765888978277, 0.597371565113501, 0.438771439968094, 
0.198886237072386, 0.515873015873038, 0.673000791765629, 0.953137410643369, 
1.54823342596267, 1.10540860639556, 1.37632717263074, 1.73092053501181, 
1.72009382329947, 2.53807106598985, 2.01706749418153, 1.6627996906419, 
1.99846272098384, 1.29474485910129, 1.21673003802282, 1.17915557246102, 
1.13036925395631, 0.789473684210527, 1.05184072126221, 1.16541353383457, 
0.968703427719814, 1.86497575531517, 1.82156133828996, 2.0066889632107, 
1.62361623616237, 1.24496521420726, 1.64293537787514, 1.67577413479055, 
1.70660856935367, 1.84448462929475, 1.4727011494253, 1.28986026513793, 
1.7850767583006, 2.05965909090908, 2.26548672566371, 3.0774672798019, 
2.94633461943178, 2.88796102992346, 3.08065074420214, 1.61290322580647, 
0.81771720613288, 0.270544470747383, -0.235057085292139, 0.405268490374862, 
0.811084825954715, 1.11298482293424, 1.11073712554695, 1.37907837201482, 
1.87730472678512, 2.00133422281521, 2.19707057256989, 2.22295952222959, 
2.13886146758801, 1.86396337475473, 2.01954397394136, 2.01233365790325, 
1.54639175257732, 1.50882825040129, 1.62835249042147, 1.33630289532296, 
1.20558375634519, 1.07526881720429, 0.848256361922726, 0.50235478806906, 
0.0313479623824208, 0.469336670838559, 0.124610591900319, 0.312402374258052, 
0.250705108116592, 0.0934288383680993, 0.466708151835709, 1.12114606041732, 
1.87558612066271, 1.68014934660859, 1.73428305977082, 1.66307360640589, 
1.50352868978214, NA), inflation.expectations = c(NA, NA, NA, 
1.50801477605895, 1.4486785021669, 1.79929942636258, 2.29268352797792, 
2.68149874988416, 2.97304591863771, 2.9099469132521, 2.84589534341579, 
2.81856733904331, 2.7495789658949, 2.75806665088503, 2.96691160747748, 
2.72258239253178, 2.52782178251204, 2.60122881632309, 2.33637603692047, 
2.2809563176788, 2.52682764427079, 2.80794468350899, 3.2404491631377, 
3.75401310219766, 4.0007218187302, 3.80050022961972, 3.53823385027365, 
3.13540427409593, 2.57733945909728, 2.25531971126995, 1.79894135183157, 
1.54808212141362, 1.40278356856036, 1.29708142041183, 1.47023752720658, 
1.50344994807437, 1.69292268877016, 1.88217821580371, 1.91267336669823, 
2.22986050932296, 2.56111875120039, 2.92977052389075, 3.44900129312152, 
3.83575607632631, 4.26738156018238, 4.8227657308928, 5.23786007051543, 
5.45641618638834, 5.41289261654365, 5.33373470151315, 5.48114036189052, 
5.76736959518821, 6.39283917392495, 6.76509751009264, 7.02871257150183, 
7.27836673943754, 7.19772410795547, 7.20727683477527, 6.99260755649861, 
6.59846759963091, 6.39497836138823, 6.16580594956255, 5.91259446184599, 
5.74756178210743, 5.26045131191845, 4.68654167351939, 4.25423330402936, 
3.89904733664698, 3.77625358118387, 3.79383980936348, 3.73489110911043, 
3.53477584443675, 3.29843687204619, 2.96158828238886, 2.71992371304414, 
2.69806445127303, 2.80037452546369, 3.33568546077594, 4.04028983714665, 
4.69145331668506, 5.35232276300158, 5.48775864641924, 5.44375449601879, 
5.49666525898119, 5.46981256049155, 5.83927829539255, 6.33829269383454, 
6.37894166917524, 6.26738060054798, 5.87133593172104, 5.24848187187738, 
4.79079819831886, 4.27117334170428, 3.78322955182357, 3.29922236866267, 
2.99612187662476, 2.88255729385125, 2.57029186194084, 2.40887335577789, 
2.27528686988792, 2.14245535022111, 2.19036530172677, 2.06741855755544, 
1.67413087012476, 1.09822452571389, 0.495950668882792, -0.128462558533547, 
-0.442788478567812, -0.433559980967218, -0.220479791925491, 0.252408505019235, 
0.621837030662707, 0.898586392840712, 1.09171367899125, 1.27389206560372, 
1.63816822901912, 2.07273031816427, 2.4512635143885, 2.77981202846581, 
2.85500195157291, 2.71070313740094, 2.69155465915108, 2.69596081311993, 
2.72656088179111, 2.97510967786683, 3.42110702343646, 4.03989140630852, 
4.80697588314739, 5.50569842832758, 5.61669571930115, 5.07470807822327, 
4.76350908108148, 4.33678538842974, 4.23326106953342, 4.47538860000716, 
4.05188141186136, 3.64833352971859, 3.15791997652761, 2.69432651752064, 
2.47126859072756, 2.21015247872182, 1.95271693597557, 1.7072614326955, 
1.55113773030694, 1.48163208739043, 1.43439700925698, 1.44976034765444, 
1.52650875432088, 1.55196150345481, 1.79187782246058, 1.93886183072177, 
1.81041049277125, 1.7642533197921, 1.33291161449346, 0.913072906257374, 
0.650672032984188, 0.437725564506755, 0.456632871169787, 0.585224363838606, 
0.922561161061177, 1.06994505869181, 1.24577665390808, 1.4402224350002, 
1.48318753433439, 1.84135314923297, 2.00153822962066, 1.98450801852819, 
2.05410024294928, 1.74326869122714, 1.54318432718746, 1.42227329764224, 
1.20524993088536, 1.07893213716267, 1.03770980797252, 1.0342742983159, 
0.99385784175678, 1.26273335953294, 1.45516351378988, 1.66548237113391, 
1.82921057324455, 1.67420793796757, 1.62955144786387, 1.54682274075883, 
1.56757082405666, 1.71745067782853, 1.67489212071607, 1.57841365330291, 
1.59803070053965, 1.65182431594323, 1.85002071000283, 2.29692246366882, 
2.58723692895162, 2.79431241370521, 2.99810341833982, 2.63196240484096, 
2.09980805151624, 1.44545391172222, 0.616526954348648, 0.314618270490747, 
0.312960175446205, 0.52357026349292, 0.860018816202692, 1.10347128661268, 
1.37002626182028, 1.59211361179053, 1.86369697354626, 2.07466726109995, 
2.14005644630068, 2.10571373428556, 2.06133208462842, 2.00867561854684, 
1.86055818979416, 1.7717744087058, 1.67397653782583, 1.50496884718076, 
1.41976684812273, 1.31137698982348, 1.11635295769879, 0.907865930885317, 
0.614306982394624, 0.462823945803191, 0.28191250329759, 0.234424399844838, 
0.289263686278381, 0.195286728160766, 0.280811118144613, 0.48299703968443, 
0.88921729282096, 1.28589741988108, 1.60279114686486, 1.738273033362, 
1.64525867564186, NA), interest = c(NA, 5.35557238134039, 5.65423925618318, 
5.13622072240136, 4.55413642305029, 3.71787392697849, 3.26037157258996, 
3.28095420515844, 3.29783174035887, 3.47781738532444, 3.49437293612889, 
3.72163754549162, 3.84408249017092, 4.06690790851614, 4.1446596728808, 
4.27721536907248, 4.14623030125552, 4.09449240844335, 4.18560930660039, 
4.63981100054776, 4.7121323361927, 5.12883105832718, 5.54727355900921, 
5.92290660730055, 6.22341845137662, 7.11106593622199, 7.3253747617984, 
7.13042433548532, 5.97172051411505, 4.56712297046551, 3.8558656869252, 
3.51957985417817, 3.8610891554008, 4.02174474418486, 3.82346231316841, 
4.23658606616291, 4.22829946772347, 5.18790684145203, 6.78957755021998, 
8.0955777116722, 10.1656568645963, 10.7750764991825, 9.73853260939899, 
9.02759451458681, 8.20283904090853, 7.32272118152342, 7.44606149789939, 
6.77781156936892, 5.80712176217568, 5.71513816400124, 4.50891159990188, 
7.57743921458531, 9.18435535875248, 14.0419316383852, 14.9575290056527, 
14.1178056651345, 12.6410371718056, 11.0504236028251, 9.89626938705202, 
8.89973682896865, 7.07766429233585, 5.69857669197553, 4.28836812363278, 
3.84307224425418, 4.13538427492242, 4.25898808637195, 4.68901648273106, 
4.76488566527071, 4.94389544062135, 4.7179504834868, 4.32996714101299, 
4.06006402761478, 3.79609544096395, 3.66188016268261, 3.81380424085245, 
3.91010496344097, 4.61063115980445, 6.07337353840198, 7.75557867353165, 
9.78085290211559, 10.0538566420945, 10.4046444586366, 10.0000032100844, 
10.5649304483193, 12.2918218267592, 13.6457804054952, 13.5428226016878, 
12.3832078638194, 11.2687387423951, 9.70571375727047, 9.01305530789178, 
7.50517458580322, 6.21597437782109, 5.74004242964374, 5.81014232275079, 
6.4184163977542, 6.4693089315514, 6.37037832492013, 6.34245883381412, 
6.14855766051217, 6.3273429016393, 6.04967934221401, 5.2631860335149, 
4.9875706048764, 4.78108266201254, 4.79409311085417, 4.80993832963175, 
4.70492528569579, 4.39327964091005, 4.09384666154318, 4.16225556135519, 
4.01819811978343, 3.68691767272542, 3.91435897298329, 5.51392769408741, 
5.1424233310261, 6.39039983797878, 7.24499841261201, 7.77689836874453, 
8.46503046729321, 8.67166062565128, 8.84963109457471, 9.06134228709401, 
9.33974999724725, 9.56778657130586, 9.70751735717581, 9.90866420403565, 
10.0801258989762, 10.3581635863144, 10.3971603688386, 10.3385810419606, 
9.52714136869548, 8.74932392442107, 8.11714459129194, 7.20165036633724, 
6.58574899339055, 6.05056584696069, 5.58018097698514, 5.29852094897063, 
5.38465196968898, 5.21812695674604, 4.84675059954163, 4.5913900970064, 
4.07203560184872, 3.70982915819822, 3.50266598028381, 3.38000354417156, 
3.18282229178484, 3.27314292367979, 3.32976414802579, 3.38343875901737, 
3.6586987321636, 3.64454089094062, 3.7948146158798, 3.68283501586431, 
3.43669424239905, 3.16555075952931, 2.80262109165974, 2.85641961411505, 
3.38452040878434, 3.86173549235485, 4.44541261612672, 4.89885908282544, 
5.15567643489052, 4.97271225405667, 4.72034580967617, 4.33381215892223, 
3.60685785482138, 3.53385476016745, 3.51249208281221, 3.37259127771301, 
3.19363958387131, 2.76224105709386, 2.44481466831683, 2.19806971073306, 
2.17309505810128, 2.26277062819573, 2.15259936154468, 2.19269951680376, 
2.18983785824214, 2.14000501378124, 2.18834248328099, 2.20010383661118, 
2.36143676501575, 2.68129278503981, 2.98602962054242, 3.27090641492713, 
3.63242231301262, 4.02644503599252, 4.24942586755106, 4.52690793717871, 
4.77567632144318, 5.10003373506962, 5.1346239656193, 4.94365644459258, 
4.09328685040382, 2.32600760779229, 1.4863967759591, 0.788184698576733, 
0.543001511592922, 0.774219432020606, 0.741022729446694, 0.839516748976732, 
0.970660699277159, 1.15589131520193, 1.46897151616208, 1.56401297889317, 
1.45956484816641, 1.23445225641425, 0.729965804965516, 0.375122725188359, 
0.196131285796364, 0.158516042744461, 0.191601356699955, 0.238406567316929, 
0.257749238213556, 0.257739981275096, 0.27688962968031, 0.171097229780903, 
0.0991262798613279, -0.00149597762337805, -0.0084472129191715, 
-0.025177017668776, -0.08365922680722, -0.0554751024051447, -0.249168240480735, 
-0.294869794233332, -0.324704745459981, -0.368654905707033, -0.33007257566352, 
-0.356317518522098, -0.356269651191377, -0.344226028709149)), class = "data.frame", row.names = c(NA, 
-233L))

1 个答案:

答案 0 :(得分:0)

更好的方法是将时间索引存储在文件中,但由于看起来没有完成,我们必须在代码中外部添加这些知识。让我们假设它是从1990年1月开始的月度系列。正如问题所述,您正在使用ts系列环境将其转换为具有假设开始时间和频率的"ts"类对象。现在我们可以使用na.contiguous删除前导和尾随NAs,仍然跟踪索引

tt <- ts(ger.data, start = 1990, frequency = 12)
na.contiguous(tt)

提供此"ts"课程系列:

          gdp.log   inflation inflation.expectations     interest
May 2000 12.88405  3.29915972              2.9751097  9.567786571
Jun 2000 12.88697  4.51351792              3.4211070  9.707517357
Jul 2000 12.92050  5.50437318              4.0398914  9.908664204
Aug 2000 12.94383  5.91085271              4.8069759 10.080125899
Sep 2000 12.95082  6.09404990              5.5056984 10.358163586
Oct 2000 12.95983  4.95750708              5.6166957 10.397160369
Nov 2000 12.96993  3.33642261              5.0747081 10.338581042
Dec 2000 12.97127  4.66605672              4.7635091  9.527141369
Jan 2001 12.98322  4.38715513              4.3367854  8.749323924
Feb 2001 12.99340  4.54340981              4.2332611  8.117144591
Mar 2001 12.99943  4.30493274              4.4753886  7.201650366
Apr 2001 13.01828  2.97202797              4.0518814  6.585748993
May 2001 13.02438  2.77296360              3.6483335  6.050565847
Jun 2001 13.03593  2.58175559              3.1579200  5.580180977
Jul 2001 13.05410  2.45055890              2.6943265  5.298520949
Aug 2001 13.05345  2.07979626              2.4712686  5.384651970
Sep 2001 13.07109  1.72849916              2.2101525  5.218126957
Oct 2001 13.07862  1.55201342              1.9527169  4.846750600
Nov 2001 13.07989  1.46873689              1.7072614  4.591390097
Dec 2001 13.06888  1.45530146              1.5511377  4.072035602
Jan 2002 13.08321  1.45047659              1.4816321  3.709829158
Feb 2002 13.09103  1.36307311              1.4343970  3.502665980
Mar 2002 13.09841  1.53019024              1.4497603  3.380003544
Apr 2002 13.09267  1.76229508              1.5265088  3.182822292
May 2002 13.10559  1.55228758              1.5519615  3.273142924
Jun 2002 13.11057  2.32273839              1.7918778  3.329764148
Jul 2002 13.11931  2.11812627              1.9388618  3.383438759
Aug 2002 13.12622  1.24848973              1.8104105  3.658698732
Sep 2002 13.12870  1.36765889              1.7642533  3.644540891
Oct 2002 13.13278  0.59737157              1.3329116  3.794814616
Nov 2002 13.13456  0.43877144              0.9130729  3.682835016
Dec 2002 13.14211  0.19888624              0.6506720  3.436694242
Jan 2003 13.14560  0.51587302              0.4377256  3.165550760
Feb 2003 13.15558  0.67300079              0.4566329  2.802621092
Mar 2003 13.16496  0.95313741              0.5852244  2.856419614
Apr 2003 13.17306  1.54823343              0.9225612  3.384520409
May 2003 13.18047  1.10540861              1.0699451  3.861735492
Jun 2003 13.18178  1.37632717              1.2457767  4.445412616
Jul 2003 13.18092  1.73092054              1.4402224  4.898859083
Aug 2003 13.20399  1.72009382              1.4831875  5.155676435
Sep 2003 13.20722  2.53807107              1.8413531  4.972712254
Oct 2003 13.21007  2.01706749              2.0015382  4.720345810
Nov 2003 13.21767  1.66279969              1.9845080  4.333812159
Dec 2003 13.21733  1.99846272              2.0541002  3.606857855
Jan 2004 13.21775  1.29474486              1.7432687  3.533854760
Feb 2004 13.22913  1.21673004              1.5431843  3.512492083
Mar 2004 13.22974  1.17915557              1.4222733  3.372591278
Apr 2004 13.22151  1.13036925              1.2052499  3.193639584
May 2004 13.22213  0.78947368              1.0789321  2.762241057
Jun 2004 13.23402  1.05184072              1.0377098  2.444814668
Jul 2004 13.23555  1.16541353              1.0342743  2.198069711
Aug 2004 13.24096  0.96870343              0.9938578  2.173095058
Sep 2004 13.24847  1.86497576              1.2627334  2.262770628
Oct 2004 13.24791  1.82156134              1.4551635  2.152599362
Nov 2004 13.24714  2.00668896              1.6654824  2.192699517
Dec 2004 13.24989  1.62361624              1.8292106  2.189837858
Jan 2005 13.25729  1.24496521              1.6742079  2.140005014
Feb 2005 13.26716  1.64293538              1.6295514  2.188342483
Mar 2005 13.26979  1.67577413              1.5468227  2.200103837
Apr 2005 13.27925  1.70660857              1.5675708  2.361436765
May 2005 13.29820  1.84448463              1.7174507  2.681292785
Jun 2005 13.30860  1.47270115              1.6748921  2.986029621
Jul 2005 13.32221  1.28986027              1.5784137  3.270906415
Aug 2005 13.33744  1.78507676              1.5980307  3.632422313
Sep 2005 13.34807  2.05965909              1.6518243  4.026445036
Oct 2005 13.35902  2.26548673              1.8500207  4.249425868
Nov 2005 13.36371  3.07746728              2.2969225  4.526907937
Dec 2005 13.37421  2.94633462              2.5872369  4.775676321
Jan 2006 13.37450  2.88796103              2.7943124  5.100033735
Feb 2006 13.37106  3.08065074              2.9981034  5.134623966
Mar 2006 13.35433  1.61290323              2.6319624  4.943656445
Apr 2006 13.31683  0.81771721              2.0998081  4.093286850
May 2006 13.32134  0.27054447              1.4454539  2.326007608
Jun 2006 13.33240 -0.23505709              0.6165270  1.486396776
Jul 2006 13.34413  0.40526849              0.3146183  0.788184699
Aug 2006 13.35055  0.81108483              0.3129602  0.543001512
Sep 2006 13.37033  1.11298482              0.5235703  0.774219432
Oct 2006 13.38341  1.11073713              0.8600188  0.741022729
Nov 2006 13.39499  1.37907837              1.1034713  0.839516749
Dec 2006 13.41332  1.87730473              1.3700263  0.970660699
Jan 2007 13.41777  2.00133422              1.5921136  1.155891315
Feb 2007 13.42693  2.19707057              1.8636970  1.468971516
Mar 2007 13.43072  2.22295952              2.0746673  1.564012979
Apr 2007 13.43711  2.13886147              2.1400564  1.459564848
May 2007 13.44110  1.86396337              2.1057137  1.234452256
Jun 2007 13.44939  2.01954397              2.0613321  0.729965805
Jul 2007 13.44944  2.01233366              2.0086756  0.375122725
Aug 2007 13.45274  1.54639175              1.8605582  0.196131286
Sep 2007 13.46584  1.50882825              1.7717744  0.158516043
Oct 2007 13.47608  1.62835249              1.6739765  0.191601357
Nov 2007 13.48412  1.33630290              1.5049688  0.238406567
Dec 2007 13.49756  1.20558376              1.4197668  0.257749238
Jan 2008 13.50076  1.07526882              1.3113770  0.257739981
Feb 2008 13.50768  0.84825636              1.1163530  0.276889630
Mar 2008 13.52027  0.50235479              0.9078659  0.171097230
Apr 2008 13.52858  0.03134796              0.6143070  0.099126280
May 2008 13.53872  0.46933667              0.4628239 -0.001495978
Jun 2008 13.54465  0.12461059              0.2819125 -0.008447213
Jul 2008 13.55343  0.31240237              0.2344244 -0.025177018
Aug 2008 13.56332  0.25070511              0.2892637 -0.083659227
Sep 2008 13.57004  0.09342884              0.1952867 -0.055475102
Oct 2008 13.57527  0.46670815              0.2808111 -0.249168240
Nov 2008 13.58345  1.12114606              0.4829970 -0.294869794
Dec 2008 13.59366  1.87558612              0.8892173 -0.324704745
Jan 2009 13.60818  1.68014935              1.2858974 -0.368654906
Feb 2009 13.62189  1.73428306              1.6027911 -0.330072576
Mar 2009 13.62858  1.66307361              1.7382730 -0.356317519

注意

请注意,我们可以使用以下代码写出tt索引:

library(zoo)
write.zoo(as.zoo(tt), "myfile.csv", sep = ",")

并使用以下方式阅读:

z <- read.csv.zoo("myfile.csv", FUN = as.yearmon, format = "%b %Y")
as.ts(z)

这样就不必将开始和频率硬编码到程序中。