Skip to content
Prev 3290 / 15274 Next

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: