下面是我相当大的表的一部分,称为“输入”:
[,1] [,2] [,3]
[7146,] 20100324 7.70 4.0000000
[7147,] 20100324 2.22 0.0000000
[7148,] 20100325 2.12 0.0000000
[7149,] 20100326 2.29 0.0000000
[7150,] 20100327 2.10 0.0000000
[7151,] 20100328 2.26 2.0000000
[7152,] 20100328 2.01 1.6000000
[7153,] 20100328 2.17 0.0000000
[7154,] 20100329 1.92 0.0000000
[7155,] 20100330 2.15 0.0000000
我想做的是如下:
我想聚合具有相同日期的行(日期在列 [,1] 中说明)并将列 [,2] 和 [,3] 中这些行的值相加除以聚合的行数。
输出将是这样的:
[,1] [,2] [,3]
[1,] 20100324 4.96 2.0000000 # e.g: [1,2] = (input[7146,2] + input[7147,2])/2 = (7.70
[2,] 20100325 2.12 0.0000000 + 2.22)/2 = 4.96
[3,] 20100326 2.29 0.0000000
[4,] 20100327 2.10 0.0000000
[5,] 20100328 2.15 1.2000000
[6,] 20100329 1.92 0.0000000
[7,] 20100330 2.15 0.0000000
非常感谢您的帮助!