[R] how apply.monthly() in package xts works
Joshua Ulrich
josh.m.ulrich at gmail.com
Wed May 3 17:00:09 CEST 2017
On Thu, Mar 9, 2017 at 9:03 PM, Joshua Ulrich <josh.m.ulrich at gmail.com> wrote:
> On Thu, Mar 9, 2017 at 3:46 PM, Joshua Ulrich <josh.m.ulrich at gmail.com> wrote:
>> On Thu, Mar 9, 2017 at 3:31 PM, Waichler, Scott R
>> <Scott.Waichler at pnnl.gov> wrote:
>>> Hi,
>>>
>>> I found that apply.monthly() in xts does not work as I expected in the case of a sparse timeseries:
>>>
>>> my.dates <- as.Date(c("1992-06-01", "1992-06-24", "1992-06-30", "1993-06-22", "1994-06-07", "1995-06-08"))
>>> my.xts <- xts(1:6, my.dates)
>>> start(my.xts) # "1992-06-24"
>>> end(my.xts) # "1995-06-08"
>>> apply.monthly(my.xts, mean)
>>> # [,1]
>>> # 1995-06-08 3.5
>>>
>>> The endpoints it chooses are based on looking at the month (June) alone. I was able to get a value for each (month, year) in the timeseries with the following use of aggregate():
>>>
>> Thanks for the minimal, reproducible example! This is clearly a bug.
>>
> Now formally documented as such:
> https://github.com/joshuaulrich/xts/issues/169
>
And now fixed. Will be in the next release.
Thanks again for the report!
<snip>
--
Joshua Ulrich | about.me/joshuaulrich
FOSS Trading | www.fosstrading.com
R/Finance 2017 | www.rinfinance.com
More information about the R-help
mailing list