子向量之和

时间:2015-04-01 19:08:26

标签: r

我的向量包含某个月某个事件的每日频率。

我想看看16天的运行频率是多少,我想提取开始en和它的日期。

vector=table(date[year(date)==2001&month(date)==05])

我知道怎么做,但我的方法(显然)太原始了。

max(c(sum(vector[1:16]),sum(vector[2:17]),sum(vector[3:18]),sum(vector[4:19]),sum(vector[5:20]),sum(vector[6:21]))/sum(vector))

编辑:为了重现性,矢量中的数据以下面的.csv格式提供:

"","Var1","Freq"
"1","2001-05-06",1
"2","2001-05-08",1
"3","2001-05-09",7
"4","2001-05-10",2
"5","2001-05-11",10
"6","2001-05-12",10
"7","2001-05-13",7
"8","2001-05-14",20
"9","2001-05-15",24
"10","2001-05-16",15
"11","2001-05-17",27
"12","2001-05-18",17
"13","2001-05-19",13
"14","2001-05-20",15
"15","2001-05-21",13
"16","2001-05-22",26
"17","2001-05-23",17
"18","2001-05-24",19
"19","2001-05-25",7
"20","2001-05-26",5
"21","2001-05-27",6
"22","2001-05-28",2
"23","2001-05-29",1
"24","2001-05-31",1

1 个答案:

答案 0 :(得分:1)

假设vector中的数据如您的数据示例中所示,类似

max_start <- which.max(rollmean(vector$Freq, 16, align="left"))
date_max_start <- vector$Var1[max_start] 
date_max_end <- vector$Var1[max_start + 16]