I am trying to get statistics about a weeks worth of data from a time series that only has daily values. Can someone explain how to correctly pass the weekly values to ddply (or use another method) to get output that looks something like below?
library(quantmod)
symbols<-c("USD/EUR")
data<-getSymbols(symbols, src="oanda",index.class="POSIXct",env=NULL)
symbols<-gsub("/","",symbols)
data<-as.data.frame(data)
weekly.data<-as.Date(cut(as.Date(rownames(data)),breaks = "week"))
library(plyr)
ddply(weekly.data, .(weekly.data), function(x)paste0(x))
> head(data,14)
USD.EUR
2015-01-14 0.8489
2015-01-15 0.8535
2015-01-16 0.8621
2015-01-17 0.8645
2015-01-18 0.8645
2015-01-19 0.8630
2015-01-20 0.8635
2015-01-21 0.8639
2015-01-22 0.8658
2015-01-23 0.8855
2015-01-24 0.8923
2015-01-25 0.8923
2015-01-26 0.8913
2015-01-27 0.8855
GOAL for the first full week (19th to 25th Monday to Sunday):
Open High Low Close
2015-01-19 0.8630 0.8923 0.8630 0.8923
Notes:
- Date is the first day of the week (always a Monday)
- A week is 7 days long (Monday to Sunday)
- Open is the price on the first day of the week
- High is the highest price of the week
- Low is the lowest price of the week
- Close is the last price of the week