Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/76.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R xts错误-请帮助解释行为_R_Xts - Fatal编程技术网

R xts错误-请帮助解释行为

R xts错误-请帮助解释行为,r,xts,R,Xts,我的R版本是2.15.1,我正在学习路易斯·托戈关于“预测股市回报”的案例研究。当我尝试从csv文件或web导入数据集时,这两种方法都会失败 Error in as.POSIXlt.character(x, tz, ...) : character string is not in a standard unambiguous format 我继续使用可用的.RData文件。但是,当我尝试运行T.ind函数时,我会遇到相同的错误 > T.ind <- function(quo

我的R版本是2.15.1,我正在学习路易斯·托戈关于“预测股市回报”的案例研究。当我尝试从csv文件或web导入数据集时,这两种方法都会失败

Error in as.POSIXlt.character(x, tz, ...) : 
  character string is not in a standard unambiguous format
我继续使用可用的.RData文件。但是,当我尝试运行T.ind函数时,我会遇到相同的错误

> T.ind <- function(quotes, tgt.margin = 0.025, n.days = 10) {
+ v <- apply(HLC(quotes), 1, mean)
+ r <- matrix(NA, ncol = n.days, nrow = NROW(quotes))
+ for (x in 1:n.days) r[, x] <- Next(Delt(v, k = x), x)
+ x <- apply(r, 1, function(x) sum(x[x > tgt.margin | x <
+ -tgt.margin]))
+ if (is.xts(quotes))
+ xts(x, time(quotes))
+ else x
+ }
令人惊讶的是,经过多次尝试和错误后,我发现删除2行可以使它工作

 > GSPC_new<-GSPC[-c(1073,1325),]
 > x_new<-x[-c(1073,1325)]
 > xts_obj<-xts(x_new,time(GSPC_new))

>GSPC_new x_new xts_obj错误来自
as.POSIXlt.character
,这是将字符数据强制到
POSIXlt
对象(即R可以理解为日期时间而不仅仅是字符串)时调用的方法

这意味着您的日期时间数据向量没有以标准日期时间格式记录:

else if (all(!is.na(strptime(xx, f <- "%Y-%m-%d %H:%M:%OS", 
    tz = tz))) || all(!is.na(strptime(xx, f <- "%Y/%m/%d %H:%M:%OS", 
    tz = tz))) || all(!is.na(strptime(xx, f <- "%Y-%m-%d %H:%M", 
    tz = tz))) || all(!is.na(strptime(xx, f <- "%Y/%m/%d %H:%M", 
    tz = tz))) || all(!is.na(strptime(xx, f <- "%Y-%m-%d", 
    tz = tz))) || all(!is.na(strptime(xx, f <- "%Y/%m/%d", 
    tz = tz)))) {

else if(all(!is.na)(strtime(xx,f感谢Gavin,你说得对,问题出在时区。我的系统时区是“CST”。更改为“GMT”后,它没有删除两行。导致问题的行包含以下日期:“1974-04-01”和“1975-04-01”。为什么这两个日期可能导致“CST”格式的问题,而不是“GMT”格式的问题?请在我有两次约会。这只是半个解释,但我想这是相关的。谢谢你的链接,达伦!
else if (all(!is.na(strptime(xx, f <- "%Y-%m-%d %H:%M:%OS", 
    tz = tz))) || all(!is.na(strptime(xx, f <- "%Y/%m/%d %H:%M:%OS", 
    tz = tz))) || all(!is.na(strptime(xx, f <- "%Y-%m-%d %H:%M", 
    tz = tz))) || all(!is.na(strptime(xx, f <- "%Y/%m/%d %H:%M", 
    tz = tz))) || all(!is.na(strptime(xx, f <- "%Y-%m-%d", 
    tz = tz))) || all(!is.na(strptime(xx, f <- "%Y/%m/%d", 
    tz = tz)))) {