Question

Have a monthly serie and I want to create a zoo serie with dates row, with daily serie a make this:

dailyserie<- as.numeric(1:365)
x.Date <- as.Date("2003-01-01") + c(1:365) - 1
Zooserie <- zoo(dailyserie, x.Date)

I have a monthly serie for 1974 to 1989, how to do it above but with months?

Thanks!

Was it helpful?

Solution

You can use seq.Date to generate a sequence of monthly dates :

from <- as.Date("1974-01-01")
to <- as.Date("1989-12-31")
months <- seq.Date(from=from,to=to,by="month")

values <- rep.int(0,length(months))

Zooserie <- zoo(values, months)

# result:
> head(Zooserie)
1974-01-01 1974-02-01 1974-03-01 1974-04-01 1974-05-01 1974-06-01 
     0          0          0          0          0          0 
> tail(Zooserie)
1989-07-01 1989-08-01 1989-09-01 1989-10-01 1989-11-01 1989-12-01 
     0          0          0          0          0          0 

Note:

seq.Date is the S3 method for generic function seq(), so, since from and to are Date object you can simply call seq() and R automatically redirects on seq.Date.

OTHER TIPS

Using zooreg and as.yearmon:

library(zoo)

values <- 1:192 # replace with your values
zooreg(values, as.yearmon("1974-01"), freq = 12)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top