r - Keep Dates when aggregating xts object -


i have xts object want aggregate data--while keeping dates.

wln = apply(dln, 2, to.weekly)  > head(wln)         aapl          gspc         vix [1,] -0.05602066 -0.0252409007  0.01903172 [2,] -0.03609222 -0.0111470571  0.13182832 

i tried using index convert dates, no avail.

as pascal commented, can use apply.weekly aggregate returns (i use period.apply below, since general solution). aggregation function use depend on how returns calculated.

require(xts) set.seed(21) x <- xts(matrix(rnorm(60, 0, 0.01), ncol=2), sys.date()-30:1) # weekly endpoints wep <- endpoints(x, "weeks") # log returns period.apply(x, wep, colsums) # arithmetic returns period.apply(x, wep, function(x) apply(1+x,2,prod)-1) 

Comments

Popular posts from this blog

javascript - Chart.js (Radar Chart) different scaleLineColor for each scaleLine -

apache - Error with PHP mail(): Multiple or malformed newlines found in additional_header -

java - Android – MapFragment overlay button shadow, just like MyLocation button -