bp.xts["2018-06"][strptime(format(index(bp.xts["2018-06"]),"%H:%M:%S"),"%H:%M:%S") > strptime("09:00:00","%H:%M:%S") & strptime(format(index(bp.xts["2018-06"]),"%H:%M:%S"),"%H:%M:%S") < strptime("12:00:00","%H:%M:%S")]
High Low Pulse
2018-06-02 10:20:00 136 91 70
2018-06-17 09:58:00 133 89 64
bp.xts[strptime(format(index(bp.xts),"%H:%M:%S"),"%H:%M:%S") > strptime("09:00:00","%H:%M:%S") & strptime(format(index(bp.xts),"%H:%M:%S"),"%H:%M:%S") < strptime("12:00:00","%H:%M:%S")]
High Low Pulse
2018-01-02 10:15:00 158 107 NA
2018-01-03 09:30:00 153 110 NA
2018-01-06 10:00:00 143 108 75
<skip....>
2018-05-26 09:33:00 126 85 73
2018-06-02 10:20:00 136 91 70
2018-06-17 09:58:00 133 89 64
> mean(na.omit(bp.xts[strptime(format(index(bp.xts),"%H:%M:%S"),"%H:%M:%S") > strptime("07:00:00","%H:%M:%S") & strptime(format(index(bp.xts),"%H:%M:%S"),"%H:%M:%S") < strptime("08:00:00","%H:%M:%S")])[,1])
[1] 126.0638
> mean(na.omit(bp.xts[strptime(format(index(bp.xts),"%H:%M:%S"),"%H:%M:%S") > strptime("08:00:00","%H:%M:%S") & strptime(format(index(bp.xts),"%H:%M:%S"),"%H:%M:%S") < strptime("09:00:00","%H:%M:%S")])[,1])
[1] 126.5357
> mean(na.omit(bp.xts[strptime(format(index(bp.xts),"%H:%M:%S"),"%H:%M:%S") > strptime("09:00:00","%H:%M:%S") & strptime(format(index(bp.xts),"%H:%M:%S"),"%H:%M:%S") < strptime("10:00:00","%H:%M:%S")])[,1])
[1] 132.1429
> mean(na.omit(bp.xts[strptime(format(index(bp.xts),"%H:%M:%S"),"%H:%M:%S") > strptime("10:00:00","%H:%M:%S") & strptime(format(index(bp.xts),"%H:%M:%S"),"%H:%M:%S") < strptime("11:00:00","%H:%M:%S")])[,1])
[1] 133.125
> time_base_mean <- function(x,y){return(mean(na.omit(bp.xts[strptime(format(index(bp.xts),"%H:%M:%S"),"%H:%M:%S") > strptime(x,"%H:%M:%S") & strptime(format(index(bp.xts),"%H:%M:%S"),"%H:%M:%S") < strptime(y,"%H:%M:%S")])[,1]))}
> time_base_mean("08:00:00","09:00:00")
[1] 126.5357
> mapply(time_base_mean, c("08:00:00","09:00:00","10:00:00"),c("09:00:00","10:00:00","11:00:00"))
08:00:00 09:00:00 10:00:00
126.5357 132.1429 133.1250
#
# use anonymous function in line
#
mapply(function(x,y){return(mean(na.omit(bp.xts[strptime(format(index(bp.xts),"%H:%M:%S"),"%H:%M:%S") > strptime(x,"%H:%M:%S") & strptime(format(index(bp.xts),"%H:%M:%S"),"%H:%M:%S") < strptime(y,"%H:%M:%S")])
[,1]))},c("05:00:00","06:00:00","07:00:00","08:00:00","09:00:00","10:00:00","11:00:00","23:00:00","00:00:00"),c("05:00:00","06:59:00","07:59:00","08:59:00","09:59:00","10:59:00","11:59:00","23:59:00","00:59:00"))
05:00:00 06:00:00 07:00:00 08:00:00 09:00:00 10:00:00 11:00:00 23:00:00 00:00:00
NaN 128.0000 125.0566 125.1176 129.8182 133.1250 132.8333 117.7000 117.4062
0 件のコメント:
コメントを投稿