Skip to content

cut range from time objects

2 messages · Dominykas Grigonis, G See

#
Hi Dominykas

I would try the below as my first attempt.

library(xts)
library(timeSeries)
Sys.setenv(TZ="GMT")
temp <- xts(1:84, timeCalendar(m=1, d=rep(1:7,each=12),h = seq(0,23,2)))

# Monday through Thursday
mt <- temp[.indexwday(temp) %in% 1:4]

# Friday 00:00:00/20:00:00
f <- temp[.indexwday(temp) == 5L]["T00:00:00/T20:00:00"]

# Sunday 20:00:00/24:00:00
s <- temp[.indexwday(temp) == 0L]["T20:00:00.000/T23:59:59.999"]

out <- rbind(mt, f, s)

# check answer by adding a column with weekday (0-6 starting on Sunday)
colnames(out) <- "temp" # have to have a column name to do the next step
out$wday <- .indexwday(out)
# Now you can look at the output and see that the only times where wday is 0
# are 20:00 or later, and the only times where wday is 5 are 20:00 or earlier
out

Hope this helps,
Garrett



On Sun, Jun 23, 2013 at 10:02 AM, Dominykas Grigonis
<dominykasgrigonis at gmail.com> wrote: