将不规则转换为常规降水时间序列

时间:2012-07-05 21:25:18

标签: r xts

我有一个xts系列,有一年的降水数据:

str(data_prec)
An ‘xts’ object from 2011-01-01 to 2011-12-31 23:55:00 containing:
  Data: num [1:105125, 1] 0 0 0 0 0 0 0 0 0 0 ...
  Indexed by objects of class: [POSIXct,POSIXt] TZ: 
  xts Attributes:  
List of 2
 $ tclass: chr [1:2] "POSIXct" "POSIXt"
 $ tzone : chr ""

部分数据如下:

2011-12-15 05:15:00, 0
2011-12-15 05:20:00, 0
2011-12-15 05:25:00, 0.1
2011-12-15 05:30:00, 1.2
2011-12-15 05:31:00, 0.2
2011-12-15 05:32:00, 0.6
2011-12-15 05:33:00, 0.1
2011-12-15 05:35:00, 0.1
2011-12-15 05:36:00, 0
2011-12-15 05:37:00, 0.6
2011-12-15 05:40:00, 0
2011-12-15 05:45:00, 0
2011-12-15 05:50:00, 0.1

我需要通过总结以前的数据,每五分钟获取一次数据。我尝试使用aggregateto.minutes5merge但没有成功。我不知道我做错了什么。这是我最接近的方式:

align.time(period.sum(data_prec,endpoints(data_prec,"minutes",k=5)),300)

那给了我:

2011-12-15 05:15:00, 0
2011-12-15 05:20:00, 0
2011-12-15 05:25:00, 0      
2011-12-15 05:30:00, 0.1    
2011-12-15 05:35:00, 2.1    
2011-12-15 05:40:00, 0.7    
2011-12-15 05:45:00, 0
2011-12-15 05:50:00, 0      
2011-12-15 05:55:00, 0.1
2011-12-15 06:00:00, 0

这就是我要找的:

2011-12-15 05:15:00, 0
2011-12-15 05:20:00, 0
2011-12-15 05:25:00, 0.1
2011-12-15 05:30:00, 1.2
2011-12-15 05:35:00, 1.0
2011-12-15 05:40:00, 0.6
2011-12-15 05:45:00, 0
2011-12-15 05:50:00, 0.1
2011-12-15 05:55:00, 0
2011-12-15 06:00:00, 0

感谢您的任何建议。

1 个答案:

答案 0 :(得分:2)

你没有始终如一地对待时代。按照设计,每分钟00分是该分钟的开始 - 例如12:00:00属于12:00:00 - 12:59:59.999999范围,又称12小时。

因此,您需要将时间缩短一段时间,以使其成为我认为您期望的方式。也就是说,你的“希望”结果也不一致(参见我的解决方案下面的补充):

<强>溶液

.index(x) <- .index(x) - 1
align.time(period.sum(x, endpoints(x,"mins",k=5)))
                [,1]
2011-12-15 05:15:00  0.0
2011-12-15 05:20:00  0.0
2011-12-15 05:25:00  0.1
2011-12-15 05:30:00  1.2
2011-12-15 05:35:00  1.0
2011-12-15 05:40:00  0.6
2011-12-15 05:45:00  0.0
2011-12-15 05:50:00  0.1

您的问题

sum(data_prec)  # the sample data you gave (well, not really gave in reproducible form)
[1] 3.0

# your addition
0.1 + 1.2 + 1 + 0.7 + .1
[1] 3.1

HTH