Hi, I'd like to make a time series at an annual frequency.> a<-xts(x=c(2,4,5), order.by=c("1991","1992","1993"))Error in xts(x = c(2, 4, 5), order.by = c("1991", "1992", "1993")) : order.by requires an appropriate time-based object> a<-xts(x=c(2,4,5), order.by=1991:1993)Error in xts(x = c(2, 4, 5), order.by = 1991:1993) : order.by requires an appropriate time-based object How should I do it? I know that to do for quarterly or monthly time series, we use as.yearqtr or as.yearmon. What about annual? Thanks, John [[alternative HTML version deleted]]
Eric Berger
2017-Oct-06  07:26 UTC
[R] Time series: xts/zoo object at annual (yearly) frequency
Hi John,
Here's one way to do it:
vec <- c(2,4,5)
yrs <- seq(from=as.Date("1991-01-01"),by="1
year",length=length(vec))
a <-  xts(x=vec, order.by=yrs)
HTH,
Eric
On Fri, Oct 6, 2017 at 9:56 AM, John <miaojpm at gmail.com> wrote:
> Hi,
>
>    I'd like to make a time series at an annual frequency.
>
> > a<-xts(x=c(2,4,5),
order.by=c("1991","1992","1993"))
> Error in xts(x = c(2, 4, 5), order.by = c("1991",
"1992", "1993")) :
>   order.by requires an appropriate time-based object
> > a<-xts(x=c(2,4,5), order.by=1991:1993)
> Error in xts(x = c(2, 4, 5), order.by = 1991:1993) :
>   order.by requires an appropriate time-based object
>
>   How should I do it? I know that to do for quarterly or monthly time
> series, we use as.yearqtr or as.yearmon. What about annual?
>
>    Thanks,
>
> John
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.
>
	[[alternative HTML version deleted]]
Gabor Grothendieck
2017-Oct-06  12:50 UTC
[R] Time series: xts/zoo object at annual (yearly) frequency
Maybe one of these are close enough: xts(c(2, 4, 5), yearqtr(1991:1993)) as.xts(ts(c(2, 4, 5), 1991)) of if you want only a plain year as the index then then use zoo, zooreg or ts class: library(zoo) zoo(c(2, 4, 5), 1991:1993) zooreg(c(2, 4, 5), 1991) ts(c(2, 4, 5), 1991) On Fri, Oct 6, 2017 at 2:56 AM, John <miaojpm at gmail.com> wrote:> Hi, > > I'd like to make a time series at an annual frequency. > >> a<-xts(x=c(2,4,5), order.by=c("1991","1992","1993")) > Error in xts(x = c(2, 4, 5), order.by = c("1991", "1992", "1993")) : > order.by requires an appropriate time-based object >> a<-xts(x=c(2,4,5), order.by=1991:1993) > Error in xts(x = c(2, 4, 5), order.by = 1991:1993) : > order.by requires an appropriate time-based object > > How should I do it? I know that to do for quarterly or monthly time > series, we use as.yearqtr or as.yearmon. What about annual? > > Thanks, > > John > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > 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.-- Statistics & Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com