r - Zooreg frequency warning -


suppose have following set of data:

date <- structure(c(1986, 1986.08333333333, 1986.16666666667), class = "yearmon")  return <- structure(c(0.000827577426231287, 0.00386371801344005, 0.00382634819565989 ), .dim = 3l, .dimnames = list(c("1986-01", "1986-02", "1986-03" ))) 

i used following transform return array zoo/zooreg object:

zooreg(return, order.by = date)

it provides correct output warning:

 jan 1986     feb 1986     mar 1986  0.0008275774 0.0038637180 0.0038263482  

warning message: in zoo(data, order.by, frequency) : “order.by” , “frequency” not match: “frequency” ignored

the series strictly regular , order.by , frequency should match still couldn't figure out why there warning.

according documentation (?yearmon):

the "yearmon" class used represent monthly data. internally holds data year plus 0 january, 1/12 february, 2/12 march , on in order internal representation same ts class frequency = 12.

calling:

zooreg(return, order.by = date) 

is equivalent calling

zoo(return, order.by = date, frequency = 1) 

according documentation zoo under arguments::frequency :

if specified, checked whether order.by , frequency comply.

hence warning. rid of warning, use

z <- zooreg(return, order.by = date, frequency = 12) 

or

z <- zoo(return, order.by = date, frequency = 12) 

both of these return object of class zooreg:

str(z) ‘zooreg’ series jan 1986 mar 1986   data: named num [1:3] 0.000828 0.003864 0.003826  - attr(*, "names")= chr [1:3] "1986-01" "1986-02" "1986-03"   index: class 'yearmon'  num [1:3] 1986 1986 1986   frequency: 12  

which according documentation (?zoo),

this subclass of "zoo" relies on having "zoo" series additional "frequency" attribute (which has comply index of series)

i believe want.

note calling mismatched "order.by" , "frequency" using

z <- zooreg(return, order.by = date) 

you zoo object:

str(z) ‘zoo’ series jan 1986 mar 1986   data: named num [1:3] 0.000828 0.003864 0.003826  - attr(*, "names")= chr [1:3] "1986-01" "1986-02" "1986-03"   index: class 'yearmon'  num [1:3] 1986 1986 1986 

Comments

Popular posts from this blog

java - Jasper subreport showing only one entry from the JSON data source when embedded in the Title band -

mapreduce - Resource manager does not transit to active state from standby -

serialization - Convert Any type in scala to Array[Byte] and back -