Skip to content

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

3 messages · Douglas Karabasz, R. Michael Weylandt

#
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
#
On Mon, Aug 6, 2012 at 4:30 PM, R. Michael Weylandt
<michael.weylandt at gmail.com> wrote:
To clarify that's not _why_ that looses the time-stamps (and
"xts"-ness) but just that it does happen. Technically, it's because
"dim<-.xts" doesn't exist; the reason it doesn't (I'd imagine) is
because of the time stamp thing.

M