无法再将数据框转换为xts对象

时间:2015-05-21 00:32:03

标签: r xts

我在几个月前编写了一个将数据帧转换为xts对象的函数。它曾经工作,现在,它不再工作。我不知道如何解决它。我再次安装了xts包,但没有用。我搜索了stackoverflow并用Google搜索了它。我会感激任何帮助。

谢谢!

这是我得到的错误:

Error in .Call("dimnames_zoo", x) : 
"dimnames_zoo" not resolved from current namespace (xts) 

这是我的功能:

MakeXts<-function(data){

  library(xts)

  data$Date<-strptime(paste(data$Date,data$Time),"%m/%d/%Y %H:%M:%S")
  data<-data[,-2] 
  data.xts<-xts(data[,-1],order.by=as.POSIXct(data[,1]))

  return (data.xts)

}

这是我的代码:

myData.xts <- MakeXts(myData)

和数据:

myData <- structure(list(Date = c("02/12/2015", "02/12/2015", "02/12/2015", 
"02/12/2015", "02/12/2015", "02/12/2015", "02/12/2015", "02/12/2015", 
"02/12/2015", "02/12/2015", "02/12/2015", "02/12/2015", "02/12/2015", 
"02/12/2015", "02/12/2015", "02/12/2015", "02/12/2015", "02/12/2015", 
"02/12/2015", "02/12/2015", "02/12/2015", "02/12/2015", "02/12/2015", 
"02/12/2015", "02/12/2015", "02/12/2015", "02/12/2015", "02/12/2015", 
"02/12/2015", "02/12/2015"), Time = c("16:00:00", "16:00:12", 
"16:00:46", "16:00:49", "16:01:18", "16:01:25", "16:02:00", "16:02:00", 
"16:02:00", "16:02:06", "16:03:02", "16:03:02", "16:03:02", "16:03:02", 
"16:03:02", "16:03:02", "16:03:19", "16:03:22", "16:03:22", "16:03:22", 
"16:03:22", "16:03:48", "16:04:38", "16:04:56", "16:05:30", "16:06:44", 
"16:06:58", "16:07:16", "16:08:53", "16:09:06"), Open = c(2082.75, 
2082.5, 2082.5, 2082.75, 2082.75, 2082.75, 2082.75, 2082.75, 
2082.75, 2082.75, 2083, 2083, 2083, 2083, 2083, 2083, 2082.75, 
2082.5, 2082.5, 2082.5, 2082.5, 2082.25, 2082.5, 2082.5, 2082.25, 
2082.25, 2082.5, 2082.25, 2082.75, 2082.5), High = c(2082.75, 
2082.5, 2082.75, 2082.75, 2082.75, 2082.75, 2082.75, 2082.75, 
2083, 2082.75, 2083, 2083, 2083, 2083, 2083, 2083, 2082.75, 2082.5, 
2082.5, 2082.5, 2082.5, 2082.75, 2082.75, 2082.5, 2082.5, 2082.75, 
2082.75, 2082.75, 2082.75, 2082.75), Low = c(2082.5, 2082.25, 
2082.25, 2082.5, 2082.5, 2082.5, 2082.75, 2082.75, 2082.5, 2082.5, 
2083, 2082.75, 2082.75, 2083, 2082.75, 2082.75, 2082.5, 2082.5, 
2082.5, 2082.5, 2082.25, 2082.25, 2082.5, 2082.25, 2082.25, 2082.25, 
2082.5, 2082.25, 2082.5, 2082.5), Close = c(2082.5, 2082.5, 2082.5, 
2082.75, 2082.75, 2082.75, 2082.75, 2082.75, 2082.75, 2082.75, 
2083, 2082.75, 2082.75, 2083, 2082.75, 2082.75, 2082.5, 2082.5, 
2082.5, 2082.5, 2082.25, 2082.5, 2082.5, 2082.25, 2082.5, 2082.5, 
2082.5, 2082.75, 2082.5, 2082.5)), .Names = c("Date", "Time", 
"Open", "High", "Low", "Close"), row.names = c(NA, 30L), class = "data.frame")

这是我的sessionInfo():

R version 3.1.2 (2014-10-31)
Platform: x86_64-w64-mingw32/x64 (64-bit)

locale:
[1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252    LC_MONETARY=English_United States.1252 LC_NUMERIC=C                           LC_TIME=English_United States.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] xts_0.9-7        zoo_1.7-11       moments_0.14     data.table_1.9.4 Rcpp_0.11.1     

loaded via a namespace (and not attached):
[1] chron_2.3-45    grid_3.1.2      lattice_0.20-29 plyr_1.8.1      reshape2_1.4    stringr_0.6.2   tools_3.1.2 

0 个答案:

没有答案