R time series period subtract?

Dreampuf

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.

Updated

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 ?)

agstudy

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]

編集
0

コメントを追加

0

関連記事

分類Dev

Subtract time in r

分類Dev

R: time series with value

分類Dev

Reshape of Time series in R

分類Dev

Expand a time series by specified time lengths in R

分類Dev

Rolling average by time period rather than observation in R

分類Dev

decompose() for time series: ValueError: You must specify a period or x must be a pandas object with a DatetimeIndex with a freq not set to None

分類Dev

R - align time series with different frequencies

分類Dev

Resampling time series with xts and zoo packages in R

分類Dev

How to average time series by groups in R

分類Dev

Conditional cumulative and time series columns in R

分類Dev

TIme series data in R, problems with dates

分類Dev

Estimating correlation matrix in R with time series?

分類Dev

Check if Time Period Overlaps

分類Dev

R Subtract Rows

分類Dev

Passing different forecasting method to hierarchical time series forecast in R?

分類Dev

R: How to get the maximum value of a datetime column in a time series data

分類Dev

kmeans returns an error for my time-series data sets in R

分類Dev

measure the best prediction method in R for a lot of time series

分類Dev

ElasticSearch for Time Series Data

分類Dev

Disaggregate in the context of a time series

分類Dev

Time Series "status" calculation

分類Dev

Time Series by group

分類Dev

for loop in irregular time series

分類Dev

Convert frequency to java.time.Period type

分類Dev

Laravel - caching external data in a model for a period of time

分類Dev

Function not waiting for intended period of time - Python Selenium

分類Dev

Check if date already exists in another time period

分類Dev

Monitors "sleep" after no external input for a period of time

分類Dev

Sql query - getting history data with time period

Related 関連記事

  1. 1

    Subtract time in r

  2. 2

    R: time series with value

  3. 3

    Reshape of Time series in R

  4. 4

    Expand a time series by specified time lengths in R

  5. 5

    Rolling average by time period rather than observation in R

  6. 6

    decompose() for time series: ValueError: You must specify a period or x must be a pandas object with a DatetimeIndex with a freq not set to None

  7. 7

    R - align time series with different frequencies

  8. 8

    Resampling time series with xts and zoo packages in R

  9. 9

    How to average time series by groups in R

  10. 10

    Conditional cumulative and time series columns in R

  11. 11

    TIme series data in R, problems with dates

  12. 12

    Estimating correlation matrix in R with time series?

  13. 13

    Check if Time Period Overlaps

  14. 14

    R Subtract Rows

  15. 15

    Passing different forecasting method to hierarchical time series forecast in R?

  16. 16

    R: How to get the maximum value of a datetime column in a time series data

  17. 17

    kmeans returns an error for my time-series data sets in R

  18. 18

    measure the best prediction method in R for a lot of time series

  19. 19

    ElasticSearch for Time Series Data

  20. 20

    Disaggregate in the context of a time series

  21. 21

    Time Series "status" calculation

  22. 22

    Time Series by group

  23. 23

    for loop in irregular time series

  24. 24

    Convert frequency to java.time.Period type

  25. 25

    Laravel - caching external data in a model for a period of time

  26. 26

    Function not waiting for intended period of time - Python Selenium

  27. 27

    Check if date already exists in another time period

  28. 28

    Monitors "sleep" after no external input for a period of time

  29. 29

    Sql query - getting history data with time period

ホットタグ

アーカイブ