Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong description of the period.apply function returned value in the xts package #205

Closed
bobbyx27 opened this issue Aug 7, 2017 · 3 comments
Milestone

Comments

@bobbyx27
Copy link

bobbyx27 commented Aug 7, 2017

Description

Wrong description of the period.apply function returned value in the xts package user's manual

Expected behavior

It is said that one should get "A vector with length of INDEX minus 1",

Observed behavior

I get an output of length = length(INDEX) + as.numeric(tail(INDEX,1) < length(x)) (admitting x is a vector). More precisely, I observed that the returned vector is:

[ FUN(x[1:INDEX[1]]), ..., FUN(x[(INDEX[k]+1):INDEX[k+1]]), ...]

adding FUN(x[(tail(INDEX,1)+1):length(x)]) at the end if tail(INDEX,1) < length(x).

Minimal, reproducible example

Try to modify start and icr in the following:

period.apply(1:10, seq(start, 10, by = icr), mean)

Session Info

R version 3.4.1 (2017-06-30)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)

Matrix products: default

locale:
[1] LC_COLLATE=French_France.1252  LC_CTYPE=French_France.1252    LC_MONETARY=French_France.1252 LC_NUMERIC=C                  
[5] LC_TIME=French_France.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] xts_0.10-0 zoo_1.8-0 

loaded via a namespace (and not attached):
[1] compiler_3.4.1  tools_3.4.1     grid_3.4.1      lattice_0.20-35
@joshuaulrich
Copy link
Owner

Your example, period.apply(1:10, seq(start, 10, by = icr), mean), will provide unusual results whenever start != 0. This is because period.apply() expects INDEX to be similar to the output of endpoints(), which always returns a vector that has zero as the first value and nrow(x) as the last value.

Thanks for the report! I will amend the documentation.

@PhilippBuehler
Copy link

PhilippBuehler commented Dec 20, 2018

I still don't know if the description or the function itself is wrong:

From the current Description in the documentation:

...where the interval is taken to be the data from INDEX[k] to INDEX[k+1]...

According to the code, the Description should be:

...where the interval is taken to be the data from INDEX[k]**_+1_** to INDEX[k+1]...

@joshuaulrich joshuaulrich added this to the 0.12.3 milestone Oct 13, 2022
@joshuaulrich
Copy link
Owner

The description in the documentation is wrong. I'll fix. Thanks for the report!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants