There are sample data of a user's event after 3 week ago :
> subret
uid event_name date count
2 10225 _e_io 2013-07-23 2
3 10225 _e_io 2013-07-24 3
4 10225 _e_io 2013-07-25 7
5 10225 _e_io 2013-07-26 6
6 10225 _e_io 2013-07-27 11
7 10225 _e_io 2013-07-28 4
8 10225 _e_io 2013-07-29 4
9 10225 _e_io 2013-07-30 2
10 10225 _e_io 2013-07-31 3
11 10225 _e_io 2013-08-01 1
12 10225 _e_io 2013-08-02 5
13 10225 _e_io 2013-08-03 2
14 10225 _e_io 2013-08-04 9
15 10225 _e_io 2013-08-05 13
16 10225 _e_io 2013-08-06 4
17 10225 _e_io 2013-08-07 14
18 10225 _e_io 2013-08-08 15
19 10225 _e_io 2013-08-09 11
20 10225 _e_io 2013-08-10 7
21 10225 _e_io 2013-08-11 2
22 10225 _e_renderer-load 2013-08-06 3
23 10225 _e_unknown 2013-07-29 1
24 10225 _e_unknown 2013-07-31 1
25 10225 _e_unknown 2013-08-01 1
26 10225 _e_unknown 2013-08-02 1
27 10225 _e_unknown 2013-08-06 4
28 10225 _e_unknown 2013-08-08 7
29 10225 _e_unknown 2013-08-10 3
I don't know how to get the value of the weekly subtract of a event. It's hard to operation for one by one event supply the lost date count. Does R support subtract the value as a consistent key match (like merge
) ?
It's means :
> ta <- (subret[subret$event_name == "_e_io" & subret$date <= as.Date("2013-07-29"), ])
> tb <- (subret[subret$event_name == "_e_io" & subret$date > as.Date("2013-07-29") & subret$date <= as.Date("2013-08-05"), ])
> (ta$count - tb$count / ta$count)
[1] 1.000000 2.000000 6.857143 5.166667 10.818182 1.750000 0.750000
I could get the increase speed every day of a week.
Sorry for the operation priority. Speed of weekly change should be:
> ((ta$count - tb$count) / ta$count)
[1] 0.0000000 0.0000000 0.8571429 0.1666667 0.8181818 -1.2500000 -2.2500000
It's ok for _e_io
that dates of a week are fully, but for others that dates of a week are not fully. Is that true I need pad the date alignment first? (use merge
?)
Your problem is not well defined. But I guess you try to split your data by event and by week. Then for each event try to compute the count return defined by :
Count_week[i]- count_week[i+1]/count_week[i]
You can use by
to process by event, then for each week you split your time series by week ( the difficult part).
by(subret,subret$event_name,function(x){
nn <- nrow(x)
x.week <- split(x$count,cut(seq(nn),
c(seq(0,nn,7),max(nn))))
ll <- length(x.week)
res <-
if(ll >1)
lapply(seq(ll-1),function(y){
x.week[[y]]-x.week[[y+1]]/x.week[[y]]
})
else NA
})
[1]]
[1] 1.000000 2.000000 6.857143 5.166667 10.818182 1.750000 0.750000
[[2]]
[1] 0.000000 -1.666667 -14.000000 2.800000 -1.500000 8.777778 12.692308
------------------------------------------------------------------------------------------
subret$event_name: _e_renderer-load
[1] NA
------------------------------------------------------------------------------------------
subret$event_name: _e_unknown
[1] NA
Warning message:
In x.week[[y + 1]]/x.week[[y]] :
longer object length is not a multiple of shorter object length
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加