替换列中的值以更改生产率指数初始值 - R.

时间:2017-12-10 17:50:18

标签: r dataframe time-series transform

我正在进行时间序列分析。我想分析1971年至2015年的季度生产率数据。然而,生产率用2010年= 1的生产力指数表示。

这意味着2010年4季度的平均值等于1.这被认为是初始值。然后,相对于该值表示生产率的增加或减少。

> dput(head(prod_ts,179))
structure(c(0.4652, 0.4721, 0.4808, 0.4827, 0.4814, 0.493, 0.4936, 
0.5002, 0.5221, 0.5228, 0.5193, 0.518, 0.5058, 0.5152, 0.5193, 
0.5132, 0.5163, 0.5089, 0.5088, 0.517, 0.5269, 0.5229, 0.5279, 
0.5384, 0.5393, 0.5369, 0.5409, 0.5482, 0.5498, 0.5543, 0.5594, 
0.561, 0.5553, 0.5782, 0.5631, 0.5679, 0.5632, 0.5545, 0.5565, 
0.5545, 0.5552, 0.5599, 0.5707, 0.5742, 0.5787, 0.5884, 0.5916, 
0.5984, 0.6102, 0.6152, 0.6185, 0.6214, 0.6244, 0.6173, 0.6182, 
0.6247, 0.6304, 0.639, 0.6377, 0.6412, 0.6504, 0.6584, 0.6633, 
0.6736, 0.6753, 0.6815, 0.6925, 0.6937, 0.6995, 0.6978, 0.7034, 
0.7037, 0.7013, 0.6999, 0.6977, 0.6982, 0.7059, 0.7105, 0.7021, 
0.6992, 0.7016, 0.7051, 0.7098, 0.7187, 0.7285, 0.7436, 0.7518, 
0.7638, 0.7707, 0.7748, 0.7816, 0.7884, 0.7935, 0.8039, 0.8123, 
0.818, 0.8232, 0.823, 0.8284, 0.8266, 0.8345, 0.8359, 0.8399, 
0.8434, 0.8496, 0.8545, 0.8577, 0.8661, 0.8696, 0.8734, 0.8759, 
0.881, 0.8837, 0.8824, 0.8938, 0.903, 0.9101, 0.9131, 0.9129, 
0.915, 0.9218, 0.9266, 0.9323, 0.9324, 0.9371, 0.9392, 0.9467, 
0.9497, 0.956, 0.9603, 0.9689, 0.9747, 0.9744, 0.9782, 0.9788, 
0.977, 0.9814, 0.9916, 0.9977, 1.0141, 1.0108, 1.0109, 1.009, 
1.0116, 1.0214, 1.0243, 1.0276, 1.0304, 1.0295, 1.0212, 1.0097, 
0.9894, 0.979, 0.9861, 0.9883, 0.9898, 0.9982, 1.001, 0.999, 
1.0018, 1.0037, 1.005, 1.0146, 1.0144, 1.0168, 1.0088, 1.0171, 
1.0106, 1.0193, 1.0214, 1.0244, 1.0235, 1.0239, 1.0269, 1.0305, 
1.0347, 1.0309, 1.0383, 1.0358), .Tsp = c(1971, 2015.5, 4), class = "ts")

这对我的分析来说不是很有用。我希望表达1971年的季度总和,使其总和为1.然后,时间序列的所有剩余值(1972年至2015年的每个季度)表示为具有初始值的时间序列( 1971,1)。

1 个答案:

答案 0 :(得分:0)

如果我理解正确你想要平均1971年的值(Q1到Q4)为1,就像现在的2010年一样。如果是这样,这应该解决它(假设你的数据在Function Function_Name(x, y) sumx = 0 For i = x To x If y = "text1" Then sumx = x * 12 If y = "text2" Then sumx = x * 6 sumx = sumx + sumx Next i Function_Name = sumx End Function

df