Skip to content
Prev 302513 / 398503 Next

R: Help xts object Subset Date by Day of the Week

On Sun, Aug 5, 2012 at 4:49 PM, Douglas Karabasz
<douglas at sigmamonster.com> wrote:
I think what you do works, this might also be a one liner:

SPY[format(index(SPY), "%a") == "Mon", ]

Alternatively

split.default(SPY, format(index(SPY), "%a"))

creates a list of xts objects split by day of the week (Note you need
split.default here because split.xts does something different)
Unfortunately, your formatting got all chewed up by the R-help server,
which doesn't like HTML so I'm not quite sure what you want here.

Possibly some black magic like this?

SPY.CL <- Cl(SPY)

length(SPY.CL) <- 7*floor(length(SPY.CL)/7)

dim(SPY.CL) <- c(length(SPY.CL)/7, 7)

But note that this looses time stamps because each row can only have a
single time stamp.

You might also try

to.weekly()

Cheers,

Michael