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

endpoints ignore k when using quarters #279

Closed
alkment opened this issue Nov 6, 2018 · 1 comment
Closed

endpoints ignore k when using quarters #279

alkment opened this issue Nov 6, 2018 · 1 comment
Assignees
Labels
Milestone

Comments

@alkment
Copy link

alkment commented Nov 6, 2018

Description

endpoints ignores k when using on='quarters'

Expected behavior

Expecting to get the index of the endpoint of every second quarter. For example getting 0,181,365 as output from the example below.

Minimal, reproducible example

endpoints(xts(1:365,as.Date('2018-01-01')+(0:364)),'quarters',1)
[1]   0  90 181 273 365
endpoints(xts(1:365,as.Date('2018-01-01')+(0:364)),'quarters',2)
[1]   0  90 181 273 365

Possible Solution

changing the switch case to something like this might work

quarters = {
        ixqtr <- posixltindex$year * 100L + 190000L + posixltindex$mon%/%3 + 
            1
        ans=as.integer(c(0, which(diff(ixqtr) != 0), NR))
        ans[unique(c(1,1+seq_len((length(ans)-1)/k)*k,length(ans)))]
    }

Session Info

R version 3.4.4 (2018-03-15)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 16.04.5 LTS

Matrix products: default
BLAS: /usr/lib/openblas-base/libblas.so.3
LAPACK: /usr/lib/libopenblasp-r0.2.18.so

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C               LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8     LC_MONETARY=en_US.UTF-8   
 [6] LC_MESSAGES=en_US.UTF-8    LC_PAPER=en_US.UTF-8       LC_NAME=C                  LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

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

other attached packages:
[1] xts_0.11-2 zoo_1.8-4 

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

joshuaulrich commented Nov 18, 2018

Thanks for the report and suggested fix! I decided to use the same pattern as when k > 1 and on = "months". Thanks again for your contribution!

@joshuaulrich joshuaulrich added this to the 0.12-0 milestone Jul 4, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants