[R-SIG-Finance] Filtering dates/times from zoo/xts series

chrisbird chris at chrisbird.com
Mon Sep 26 10:24:23 CEST 2011


Ok, I don't know whether I'm just rested after the weekend, but after
struggling to figure this out last week I now seem to have solved it all
this morning.

My solution is as follows:

# filter the data source on time range
data_source <- data_source[.indexhour(min_hour) >= min_hour &
.indexhour(data_source) < max_hour]

# now remove any data for which there is now enough daily samples
# aggregate samples per day
day_samples <- apply.daily(as.xts(data_source[,1]),length)

# get rid of any which do not have enough samples
day_samples <- day_samples[day_samples >= min_samples_per_day]

# get day index of the remaining days
days <- .indexday(as.xts(day_samples))

# filter data by remaining days
data_source <- data_source[.indexday(as.xts(data_source[,1])) %in% days]


Any comments on whether or not this is an optimal solution or acan be
improved in any way would be appreciated.


--
View this message in context: http://r.789695.n4.nabble.com/Filtering-dates-times-from-zoo-xts-series-tp3842937p3843065.html
Sent from the Rmetrics mailing list archive at Nabble.com.



More information about the R-SIG-Finance mailing list