buildModel创建as.POSIXlt.character(x,tz,...)错误

时间:2012-12-02 22:49:20

标签: r posixct

我正在尝试重建this代码。我遇到了很多错误,但是这个错误花了我的一天。

这是产生错误的命令。

rf <- buildModel(data.model,method='randomForest',
         training.per=c(start(GSPC),index(GSPC["1999-12-31"])),
         ntree=50, importance=T)

错误和追溯:

> traceback()
8: stop("character string is not in a standard unambiguous format")
7: as.POSIXlt.character(x, tz, ...)
6: as.POSIXlt(x, tz, ...)
5: as.POSIXct(as.POSIXlt(x, tz, ...), tz, ...)
4: as.POSIXct.default(x)
3: as.POSIXct(x)
2: as.POSIXorDate(intersect(as.character(start.date.index), as.character(end.date.index)))
1: buildModel(data.model, method = "randomForest", training.per = c(start(GSPC), 
   index(GSPC["1999-12-31"])), ntree = 50, importance = T)

我查看了buildModel here的源代码:

"buildModel" <-
function(x,method,training.per,...) {

 as.POSIXorDate <- function(x) {
  class.of.index <- class(index(model.data))
  if("POSIXt" %in% class.of.index) {
    if("POSIXlt" %in% class.of.index) {
      x <- as.POSIXlt(x)
    } else {
      x <- as.POSIXct(x)
    }
  } else {
    x <- as.Date(x)
  }
  x
}

model.id=deparse(substitute(x))
if(length(training.per) != 2) stop("training.per must be of length 2");
model.data <- x@model.data;
start.date.index <- index(model.data[which(index(model.data) >= as.POSIXorDate(training.per[1]))])
end.date.index <- index(model.data[which(index(model.data) <= as.POSIXorDate(training.per[2]))])
training.dates <- as.POSIXorDate(intersect(as.character(start.date.index),
                                           as.character(end.date.index)));
method <- as.character(paste("buildModel.",method,sep=''));
training.data <- model.data[training.dates];
formula <- x@model.formula
mcall <- do.call(method,list(quantmod=x,training.data=training.data, ...));
x@fitted.model <- mcall$fitted;
x@model.inputs <- as.character(mcall$inputs);
x@build.date = as.character(Sys.time());
x@model.id <- paste(class(mcall$fitted)[length(class(mcall$fitted))],
                           as.numeric(Sys.time()),sep='');
x@training.data <- (training.dates);
invisible(x);
}

我该怎么办?

0 个答案:

没有答案