If it is an xts object I would do something like :
apply.monthly(s, function(x) last(x[ .indexmday(x) <= 15 ]))
-----Original Message-----
From: "Ilya Kipnis" [ilya.kipnis at gmail.com]
Date: 10/20/2016 11:55 AM
To: "r-sig-finance at r-project.org" <r-sig-finance at r-project.org>
Subject: [R-SIG-Finance] Closest weekly endpoint to the fifteenth of the
month
Hi there. I have a question about custom endpoints. Currently, in R, you
can set endpoints to weekly, monthly, quarterly, etc...
However, I was wondering if there was a way to do this:
Assuming you have weekly endpoints, is there a way to select, in each
month, the day closest to the fifteenth--AKA middle of the month?
Right now, my idea is to loop through each individual month, subtract 15
from each date, end pick the one closest to zero, and index it. I was
wondering if there's a more elegant method of doing this.
Thanks.
-Ilya
_______________________________________________
R-SIG-Finance at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-sig-finance
-- Subscriber-posting only. If you want to post, subscribe first.
-- Also note that this is not the r-help list where general R questions should go.