日期的POSIX表示



我正在尝试使用R timeSeries包来读取csv文件。

这是我要运行的代码:

prices <- readSeries(file='A2006-2011.csv',head=T,sep=",",format="%m/%d/%Y")

但是,它不能识别csv中的日期(下面是它的前几行)

Date    Open    High    Low Close   Volume  Adj.Close
4/4/2011    45.07   45.41   44.36   44.83   2133900 44.83
4/1/2011    44.88   45.48   44.78   45.14   2212300 45.14
3/31/2011   44.92   45.02   44.46   44.78   2194900 44.78
3/30/2011   44.79   45.17   44.65   45.09   2514100 45.09

,输出以下警告:

Warning message:
In readSeries(file = "A2006-2011.csv", head = T, sep = ",", format = "%m/%d/%Y") :
  Conversion of timestamps to timeDate objects produced only NAs.
  Are you sure you provided the proper format with argument 'format'
  or in the header of your file ?
如果有人能帮助我,我将非常感激。

老实说,我只是将Date作为字符串读入表,然后进行快速转换。例如,

> x = c("4/4/2011", "4/4/2011", "3/31/2011", "3/30/2011")
## In your case you would have prices$Date = as.Date(prices$Date, ...
> as.Date(x, "%m/%d/%Y")
[1] "2011-04-04" "2011-04-04" "2011-03-31" "2011-03-30"

试试这个包:speedR at https://r-forge.r-project.org/projects/speedr。它是一个可视化数据导入器,支持Date和POSIXct类。您还可以使用它从工作区中可视化地过滤现有的R对象。

相关内容

  • 没有找到相关文章

最新更新