[R] Daily Time Series, patterns.

arun smartpink111 at yahoo.com
Mon Dec 3 18:17:06 CET 2012


Hi,
In addition, you can use ?dayOfWeek() from library(timeDate)
set.seed(5)
quantity<-sample(c(120:220,NA),699,replace=TRUE)
Date=seq(as.Date("2011-01-01"),len=699,by="1 day")
dat3<-data.frame(Date=Date,quantity=quantity)
 nrow(dat3)
#[1] 699
library(timeDate)
dat3$tSeq<-timeSequence(dat3$Date[1],dat3$Date[699])
dat4<-dat3[isWeekday(dat3$tSeq),]

 dat4$DayWeek<-dayOfWeek(dat4$tSeq)
 head(dat4)
#         Date quantity       tSeq DayWeek
#3  2011-01-03      213 2011-01-03     Mon
#4  2011-01-04      149 2011-01-04     Tue
#5  2011-01-05      130 2011-01-05     Wed
#6  2011-01-06      191 2011-01-06     Thu
#7  2011-01-07      173 2011-01-07     Fri
#10 2011-01-10      131 2011-01-10     Mon
library(zoo)
z<-zooreg(dat4[,2],frequency=5)
plot(stl(na.approx(z),"per")) 

A.K.

----- Original Message -----
From: mekbatub <mekbatub at gmail.com>
To: r-help at r-project.org
Cc: 
Sent: Monday, December 3, 2012 8:14 AM
Subject: Re: [R] Daily Time Series, patterns.

Hi Arun, thanks again, I think we are close.
The way You gave me looks good, but I sill have one problem, look at this:

Lets say, we have data like this:

>head(dat3)

      Date       quantity
2012-03-05 65.16
2012-03-06 70.67
2012-03-08 63.66
2012-03-09 70.05
2012-03-12 61.59
2012-03-13 58.98

Then we have:
>z <- zooreg(dat3[,2], frequency = 5)
>z
1(1)     1(2)     1(3)     1(4)     1(5)     2(1)    
65.16  70.67  63.66  70.05  61.59   58.98

This is for dates:
1(1)               1(2)                1(3)               1(4)            
1(5)                2(1)    
2012-03-05 2012-03-06 2012-03-08 2012-03-09 2012-03-12 2012-03-13

Since there was no releases in 2012-03-07 (warehouse was closed)

We should have:
1(1)     1(2)     *1(4)     1(5)     1(1)     2(2) *    
65.16  70.67  63.66  70.05  61.59   58.98

So I can’t in that case use “frequency=5”. I am trying to figure out how to
assign correctly number of the week day to quantity.

I am wondering if my way of thinking is correct, maybe I should fill out
those missing values like You suggest me last time, but the problem is there
are not missing values really, for ex. if the warehouse was closed, there
was not supposed to be releases that day so there is nothing to fill out
really. 
I am wondering is it at all possible to do this in R like I am trying to do
– without data continuity.

What You think about that?



--
View this message in context: http://r.789695.n4.nabble.com/Daily-Time-Series-patterns-tp4651569p4651836.html
Sent from the R help mailing list archive at Nabble.com.

______________________________________________
R-help at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.





More information about the R-help mailing list