[R] Time series: xts/zoo object at annual (yearly) frequency

Gabor Grothendieck ggrothendieck at gmail.com
Fri Oct 6 14:50:18 CEST 2017


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



More information about the R-help mailing list