2

prices is an xts object

period.ends = endpoints(prices, 'months',k=1)

with this line i find position of the last day of the month in a time series.

How to find position of the first day of month (not always 1 of the month)? And the second day?

Thank you

Fryc
  • 93
  • 1
  • 1
  • 7
  • Does the answer here help you? http://stackoverflow.com/a/13005907/1270695 – A5C1D2H2I1M1N2O1R2T1 Feb 18 '14 at 15:46
  • The solution there was: x[.indexmday(x) == 1]. The problem is that this function use calendar day while i want the first day of month whatever calendar day it is – Fryc Feb 18 '14 at 17:18
  • You didn't look at the "update" in the answer that I had linked directly to, I guess.... – A5C1D2H2I1M1N2O1R2T1 Feb 18 '14 at 17:23
  • ok, sorry. lapply(split(prices, "months"), function(x) x[1]): with this i extract the first day of month (all the row of data). But my objective is to determine the position of all the first day of month in my original xts time series – Fryc Feb 18 '14 at 17:43

1 Answers1

2
startpoints <- function (x, on = "months", k = 1) {
  head(endpoints(x, on, k) + 1, -1)
}

period.starts = startpoints(prices, 'months', k=1)

See also: xts:::startof and xts::firstof

GSee
  • 48,880
  • 13
  • 125
  • 145