I extended the time series class to form a new class
called data.analysis class. I would like a
extraction method on this new class to be well
defined. I am getting an error message when I run
this method. I also include the code for my new
class.
Thanks.
Joe
setMethod("[", "data.analysis" ,function(x, ..., drop
= T)
# drop argument is ignored when subscripting time
series!
ndots <- nDotArgs(...)
if(ndots < 1)
return(x)
args <- match.call(function(x, i, j, drop)
{
}
)
if(!is.null(args$i)) {
i <- eval(args$i, sys.parent(1))
if(is.null(i))
i <- 0
}
else i <- NULL
if(!is.null(args$j)) {
j <- eval(args$j, sys.parent(1))
if(is.null(j))
j <- 0
}
else j <- NULL
# if i,j args are time series, convert them
if(is(i, "series")) i <- seriesData(i)
if(is(j, "series")) j <- seriesData(j)
if(!is.null(i)) x@positions <- x@positions[i]
oldnames <- colIds(x@data)
names(oldnames) <- oldnames
if(!is.null(i) && !is.null(j))
x@data <- asSeriesData(sub(x@data, i, j))
else if(is.null(i) && !is.null(j))
x@data <- asSeriesData(sub(x@data, , j))
else if(!is.null(i) && is.null(j))
x@data <- asSeriesData(sub(x@data, i, ))
if(!is.null(j))
newnames <- oldnames[j]
else newnames <- oldnames
names(newnames) <- NULL
nc <- numCols(x@data)
# may have ended up with a null data matrix here
if(!is.data.frame(x@data) && !is.null(newnames))
rowIds(x@data) <- character(0)
if(nc && !is.null(newnames))
colIds(x@data) <- newnames[1:nc]
x
)
#############################################3
new class to use the extraction method
setClass("data.analysis", representation=
representation("series",factors= "character"),
prototype = list("data" = matrix(NULL, nrow = 0,
ncol = 1)
, "positions" = NULL
, "start.position" = NULL
, "end.position" = NULL
, "future.positions" = NULL
, "units" = character(0)
, "title" = character(0)
, "documentation" = character(0)
, "attributes" = NULL
, contains = list("seriesVirtual" = numeric(0))
) )
__________________________________
Yahoo! Mail
Stay connected, organized, and protected. Take the tour:
http://tour.mail.yahoo.com/mailtour.html
|