how to extract the last day of the month in a last of dates?
Hi Patzoul,
library(xts)
ep <- endpoints(yourdata, on='months')
yourdata[ep, ]
?endpoints
endpoints package:xts R Documentation
Locate Endpoints by Time
Description:
Extract index values of a given 'xts' object corresponding to the
_last_ observations given a period specified by 'on'
Usage:
endpoints(x, on="months", k=1)
Arguments:
x: an xts object
on: the periods endpoints to find as a character string
k: along every k-th element - see notes
Details:
'endpoints' returns a numeric vector corresponding to the _last_
observation in each period specified by 'on', with a zero added to
the beginning of the vector, and the index of the last observation
in 'x' at the end.
Valid values for the argument 'on' include: "us" (microseconds),
"microseconds", "ms" (milliseconds), "milliseconds", "secs"
(seconds), "seconds", "mins" (minutes), "minutes", "hours",
"days", "weeks", "months", "quarters", and "years".
Value:
A numeric vector of endpoints beginning with 0 and ending with the
a value equal to the length of the x argument.
Author(s):
Jeffrey A. Ryan
HTH
Jeff
On Sun, Nov 30, 2008 at 10:43 AM, patzoul <patzoul at free.fr> wrote:
I have a timeseries of stock data. How can I extract the last day of each
month on the series?
GMT
STOXX50E.Close GSPC.Close N225.Close BSV.Close BND.Close
GSG.Close
2007-04-10 4301 1448.4 17665 74.99 75.24
41.57
2007-04-11 4293 1438.9 17670 74.95 75.04
41.45
2007-04-12 4280 1447.8 17540 75.12 75.03
41.75
2007-04-13 4317 1452.8 17364 74.91 74.91
41.80
2007-04-16 4379 1468.3 17628 75.00 74.98
41.52
2007-04-17 4384 1471.5 17527 75.09 75.17
41.16
2007-04-18 4359 1472.5 17667 75.19 75.31
41.23
2007-04-19 4340 1470.7 17372 75.21 75.28
41.00
2007-04-20 4417 1484.3 17453 75.25 75.26
41.18
2007-04-23 4400 1480.9 17455 75.29 75.36
41.62
2007-04-24 4368 1480.4 17452 75.33 75.48
41.31
2007-04-25 4404 1495.4 17236 75.31 75.42
41.78
2007-04-26 4414 1494.2 17429 75.22 75.26
41.60
2007-04-27 4383 1494.1 17400 75.21 75.24
42.14
2007-05-01 4392 1486.3 17275 75.26 75.32
41.49
2007-05-02 4415 1495.9 17395 75.21 75.33
41.22
2007-05-07 4441 1509.5 17670 75.24 75.39
40.34
2007-05-08 4411 1507.7 17657 75.26 75.40
40.84
2007-05-09 4425 1512.6 17748 75.27 75.31
40.60
...
Thx
--
View this message in context: http://www.nabble.com/how-to-extract-the-last-day-of-the-month-in-a-last-of-dates--tp20759299p20759299.html
Sent from the Rmetrics mailing list archive at Nabble.com.
_______________________________________________ R-SIG-Finance at stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. -- If you want to post, subscribe first.
Jeffrey Ryan jeffrey.ryan at insightalgo.com ia: insight algorithmics www.insightalgo.com