我使用 quantmod getSymbols 查询 MySQL 数据库:
pot<-getSymbols(Symbols="pot",src='MySQL',user='root',password='root',dbname='data',
adjust=TRUE,db.fields=c("date","open","high","low","close","volume","time"),
auto.assign=FALSE,
field.names=c("ticker","date","time","open","high","low","close","volume"),
format="%Y%m%d")
返回:搞乱日期转换。
pot.Open pot.High pot.Low pot.Close pot.Volume pot.Adjusted
7058-02-20 “40.1700” “40.1900” “40.1000” “40.1500” “104900” “09:30:59”
7058-02-20 “40.0900” “40.1725” “40.0900” “40.1725” “13200” “09”: 31:53”
7058-02-20 “40.1900” “40.3394” “40.1800” “40.2900” “16500” “
09:32:57” 7058-02-20 “40.3000” “40.3700” “40.2400” “40.2400” “36500” " "09:33:58"
7058-02-20 "40.2600" "40.3000" "40.2000" "40.2500" "6700" "09:34:59"
7058-02-20 "40.2600" "40.3100" "40.2000" " 40.2000" " 13900" "09: 35:59"
我希望它看起来像这样:
pot.Open pot.High pot.Low pot.Close pot.Volume pot.Adjusted
2012-10-31 09:30:59 “40.1700” “40.1900” “40.1000” “40.1500” “104900” “09:30:59”
2012-10-31 09:31:53 “40.0900” “40.1725” “40.0900” “”“40.1725”“13200”“09:31:53”
2012-10-31 09:32:57“40.1900”“40.3394”“40.1800”“40.2900”“16500”“09:32:57”
2012-10- 31 09:33:58 “40.3000” “40.3700” “40.2400” “40.2400” “36500” “09:33:58”
2012-10-31 09:34:59 “40.2600” “40.3000” “40.2000” “40.2500” “ 6700” “09:34:59”
2012-10-31 09:35:59 “40.2600” “40.3100” “40. 2000""40.2000""13900""09:35:59"
我相信这与表中的日期格式(%Y%m%d)ex 有关。20121031 与 quantmod 通常期望的正常 (%Y-%m-%d) ex.2012-10-31 格式相反。文档说这可以通过 setDefaults(getSymbols.MySQL,...) 更改,但没有说明如何。有什么想法吗?