Skip to content
Prev 1058 / 15274 Next

problem aggregating daily series

Dear John Frain,
please apologize for any inconveniances caused by a bug in the 
applySeries() Function.
It doesent appear when you worj with daily records using "GMT" as FinCenter.
Try:

 myFinCenter = "GMT"
 tD = timeSequence("2006-01-01", length.out = 365)
 Data = matrix(rep(1, times = 365), ncol = 1)
 tS = timeSeries(Data, tD)
 from = timeCalendar(2006)
 to = timeLastDayInMonth(from)
 applySeries(tS, from, to, FUN = colSums, units = "N")

Now fix the bug by overwriting the last line in applySeries()
timeSeries(data = rowBind, charvec = as.character(to), units = units,
        # format = x at format, zone = "GMT", FinCenter = x at FinCenter,
        format = x at format, zone = x at FinCenter, FinCenter = x at FinCenter,
        title = x at title, documentation = x at documentation, ...)

Here is the full function:

.applySeries =
function (x, from = NULL, to = NULL, FUN = colAvgs, units = NULL,  ...)
{
    colNames = units
    if (class(x) != "timeSeries") stop("s is not a timeSeries object")
    fun = match.fun(FUN)
    j.pos = as.POSIXct(seriesPositions(x))
    j.from = as.POSIXct(from)
    j.to = as.POSIXct(to)
    y = x at Data
    pos = seriesPositions(x)
    rowNames = rownames(x at Data)
    rowBind = NULL
    for (i in 1:from at Dim) {
        test = (j.pos >= j.from[i] & j.pos <= j.to[i])
        cutted = as.matrix(y[test, ])
        ans = fun(cutted, ...)
        rowBind = rbind(rowBind, ans)
    }
    rownames(rowBind) = as.character(to)
    if (is.null(colNames)) {
        units = x at units
    }
    else {
        units = colNames
    }
    timeSeries(data = rowBind, charvec = as.character(to), units = units,
        # format = x at format, zone = "GMT", FinCenter = x at FinCenter,
        format = x at format, zone = x at FinCenter, FinCenter = x at FinCenter,
        title = x at title, documentation = x at documentation, ...)
}


# Now try:

myFinCenter = "Dublin"
tD = timeSequence("2006-01-01", length.out = 365, FinCenter = "Dublin")
Data = matrix(rep(1, times = 365), ncol = 1)
tS = timeSeries(Data, tD, zone = "Dublin", FinCenter = "Dublin")
from = timeCalendar(2006)
to = timeLastDayInMonth(from, FinCenter = "Dublin")
.applySeries(tS, from, to, FUN = colSums, units = "N")

The philosophy behind the timeSeries class is that you have two
time reference points: The first where the data were collected (zone) 
and the
second where the data willl be used (FinCenter). To circumvent 
inconsistencies
in the future, I think it will be the best to allow to specify in any 
case zone and
FinCenter through the argument list in any of the timeSeries class 
functions


Diethelm Wuertz
John C. Frain wrote: