1

请放入R这个xts对象:

afspline <- structure(c(0, -1.60475876973764e-09, 0.00359139378023358, 0.00858791466940025, 
0.00965799381183328, 0.010535272095448, 0.00353659588787858, 
0.00979116750570292, 0.011240852699161, 0.0104516005116994, 0.0104622380953218, 
0.0104904698226274, 0.0098057435302585, 0.0119057677941898, 0.0103126340048352, 
0.0111618768814921, 0.0122621970134454, 0.0121815967249689, 0.0129909707355181, 
0.0130642389578735, 0.0134884534003344, 0.0150926117044429, 0.0170046325577939, 
0.0170046325577939, 0.0142370838526206, 0.00431483622555903, 
0.017563971756934, 0.0416205619836587, 0.0422314427793702, 0.0427657923845872, 
0.0432256359226883, 0.0443604518715082, 0.0364307384452604, 0.0307197640028931, 
0.0307197640028931, 0.0281165461257376, 0.0159778039243009, 0.00922101403652893, 
0.00838850919510639, 0.00871532058603137, 0.00954517706109808, 
0.0163596264435925, 0.017043891004657, 0.0184480594227399, 0.018221131241634, 
0.0170643105, 0.0148457638464233, 0.0178063545, 0.020466892, 
0.0224545459502275, 0.0199481475, 0.0199822719774656, 0.0238568051372923, 
0.0239556558255882, 0.0239304942927439, 0.023833740069486, 0.0230473522190882, 
0.0232425435, 0.0266053294973561, 0.0271557047922354, 0.0286439774006302, 
0.0261409065414502, 0.025736215635086, 0.0271787045, 0.0278139857901469, 
0.0278182605, 0.0283023445594554, 0.0288704156282462, 0.0293943179042644, 
0.0307870196963889, 0.0303917045, 0.0327307982633284, 0.0379795334351756, 
0.0329519749362104, 0.0326204201138037, 0.0338903783909274, 0.0330625667220115, 
0.0344030424498174, 0.032072856, 0.0250664805535462, 0.01904669476438, 
0.0168474800191804, 0.0168091497541303, 0.0167626604722959, 0.0167626604722959, 
0.0168033490822265, 0.0181863900395859, 0.0348719915, 0.0397291635434953, 
0.0370430065, 0.0373946872798101, 0.0374121395, -7.26607330237845e-12, 
0, 0.00366564780227182, 0.0039315055870916, 0.00433769285932111, 
0.00447494885520145, 0.00545887732436129, 0.00917885008891576, 
0.00925457636011075, 0.00933029331764019, 0.00940599742233127, 
0.00955735291650718, 0.0110610726716925, 0.0114322177386963, 
0.0115061250597584, 0.0118005640637843, 0.0139270942245086, 0.0139948536280271, 
0.0160174627880817, 0.0162472790904816, 0.0164158026181482, 0.016746325915968, 
0.017113969674913, 0.017113969674913, 0.0178077081622012, 0.0208858205549416, 
0.021511173554133, 0.0218427780784675, 0.0217702940788138, 0.0216984926059984, 
0.0216273597309023, 0.0213492485397406, 0.0200322219669266, 0.0196370733220678, 
0.0196370733220678, 0.0194732937268993, 0.0189104645343305, 0.018787292554624, 
0.0188078636091856, 0.0190448890612609, 0.0190782258845644, 0.0193344036496631, 
0.0193373739976422, 0.0192099440935651, 0.0191658085335571, 0.0190722699298511, 
0.0195081401262803, 0.0201480278747984, 0.0205770097476179, 0.0223201510819972, 
0.0222026205278813, 0.0223233470739469, 0.025927588104295, 0.0263058567393472, 
0.0263683707858456, 0.0262534092336498, 0.0252716095892415, 0.0254504204423347, 
0.0283272157143228, 0.0288002781858092, 0.0296041311753397, 0.0285158042205689, 
0.0284185751515448, 0.028835690183425, 0.0295100433083761, 0.0297572241891966, 
0.030418428904263, 0.030736494701599, 0.0309434408846719, 0.0318612964915071, 
0.0325787084776301, 0.0342664856279427, 0.0347865945770888, 0.0348870136550823, 
0.0348890531099477, 0.0348891828106299, 0.0348877240597529, 0.0347371396292105, 
0.0342745033645604, 0.0340393576184602, 0.0343581387437379, 0.0346499686874898, 
0.0346642360793682, 0.034685642540363, 0.034685642540363, 0.0348428167619517, 
0.0351078926122667, 0.0363865901040472, 0.0375067503820163, 0.0382623515248415, 
0.0387423520663562, 0.0374121395), .Dim = c(92L, 2L), .Dimnames = list(
    NULL, c("Actual", "6M Forecast")), index = structure(c(1379681504.31843, 
1379681504.33405, 1385503200, 1385848800, 1386367200, 1386540000, 
1387749600, 1392069600, 1392156000, 1392242400, 1392328800, 1392501600, 
1394229600, 1394661600, 1394748000, 1395093600, 1397685600, 1397772000, 
1400536800, 1400882400, 1401141600, 1401660000, 1402264800, 1402264800, 
1403474400, 1405720800, 1406239200, 1407708000, 1407794400, 1407880800, 
1407967200, 1408312800, 1410127200, 1410732000, 1410732000, 1410991200, 
1412287200, 1413496800, 1413756000, 1416434400, 1416780000, 1419285600, 
1419631200, 1421618400, 1422223200, 1423605600, 1428357600, 1429912800, 
1430776800, 1435528800, 1438725600, 1439244000, 1444341600, 1445292000, 
1445810400, 1446674400, 1454623200, 1455228000, 1460325600, 1461103200, 
1464904800, 1470952800, 1473199200, 1477000800, 1480888800, 1482703200, 
1488837600, 1491170400, 1492725600, 1498428000, 1500501600, 1504821600, 
1506981600, 1508277600, 1508450400, 1508536800, 1508709600, 1510696800, 
1513807200, 1516572000, 1520460000, 1524002400, 1524175200, 1524434400, 
1524434400, 1526335200, 1529532000, 1545343200, 1561068000, 1574892000, 
1590616800, 1590703200), tzone = "", tclass = c("POSIXct", "POSIXt"
)), .indexCLASS = c("POSIXct", "POSIXt"), tclass = c("POSIXct", 
"POSIXt"), .indexTZ = "", tzone = "", class = c("xts", "zoo"))

我的目标是删除索引不唯一的行,尽管行中可以存在不同的值......我不在乎。我的第一次尝试:

ciao <- afspline[-duplicated(index(afspline)),]

括号中的表达式返回:

> duplicated(index(afspline))
 [1] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[13] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE
[25] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE
[37] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[49] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[61] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[73] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[85]  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE

我认为afspline在创建中删除了每个重复行的索引ciao,但duplicated(index(ciao))返回的一些值等于TRUE

> duplicated(index(ciao))
 [1] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[13] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE
[25] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE
[37] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[49] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[61] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[73] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE
[85] FALSE FALSE FALSE FALSE FALSE FALSE FALSE

这就像duplicated(index(afspline))没有删除它应该做的所有记录......或者我错过了其他东西?

4

1 回答 1

3

的结果duplicated()是一个逻辑向量。所以要否定它,你必须使用逻辑否定,not()即:

ciao <- afspline[not(duplicated(index(afspline))),]

您也可以!用作快捷方式:

ciao <- afspline[!(duplicated(index(afspline))),]
于 2013-09-20T13:07:48.053 回答