I'm trying to convert daily data into weekly data, but with the time interval from monday to monday.

First I download historical prices from Yahoo:

Tickername<-getSymbols("Tickeername",from="2011-12-31",to="2017-01-03",auto.assign = FALSE)

Then I convert the data into weeklY:


However, I want the weekly data start from monday 9th January 2012 (monday to monday weekly data), how can I change the time interval?

Your help is fully appreciated!

  • $\begingroup$ Why do you think that to.weekly gives you data for some other period rather than monday to sunday? Can you give an example with the real ticker and real data so it can be reproduced? $\endgroup$ – zer0hedge Mar 27 '17 at 12:02
  • $\begingroup$ Also there are plenty of similar questions there stackoverflow.com/search?q=quantmod+to.weekly $\endgroup$ – zer0hedge Mar 27 '17 at 12:09
  • $\begingroup$ install.packages("lubridate") library(lubridate) mondays = as.POSIXlt(time(Ticker))$wday == 1 indx <- c(0, which(mondays)) period.apply(Ticker, INDEX=indx, FUN=last) This worked! $\endgroup$ – Neri Kim Mar 27 '17 at 12:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.