Вот как это сделать:
options(digits.secs=3)
test <- "20160801 00:00:00.018"
as.POSIXct(test, format="%Y%m%d %H:%M:%OS")
rm(list = ls(all = TRUE))
library(timeSeries)
library(timeDate)
library(PerformanceAnalytics)
library(quantmod)
library(xts)
library(zoo)
library(tseries)
sessionInfo()
#################################################################################
R version 3.3.1 (2016-06-21)
Platform: x86_64-apple-darwin13.4.0 (64-bit)
Running under: OS X 10.12 (Sierra)
locale:
[1] en_GB.UTF-8/en_GB.UTF-8/en_GB.UTF-8/C/en_GB.UTF-8/en_GB.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] tseries_0.10-35 quantmod_0.4-6 TTR_0.23-1 PerformanceAnalytics_1.4.3541
[5] xts_0.9-7 zoo_1.7-13 timeSeries_3022.101.2 timeDate_3012.100
loaded via a namespace (and not attached):
[1] tools_3.3.1 grid_3.3.1 lattice_0.20-34 quadprog_1.5-5
###############################################################################
EURUSD <- read.csv(file="EURUSD-2016-08.csv", header=FALSE) #from TrueFX
names(EURUSD)[names(EURUSD)=="V1"] <- "Symbol"
names(EURUSD)[names(EURUSD)=="V2"] <- "Date"
names(EURUSD)[names(EURUSD)=="V3"] <- "Bid"
names(EURUSD)[names(EURUSD)=="V4"] <- "Offer"
head(EURUSD)
Symbol Date Bid Offer
1 EUR/USD 20160801 00:00:00.018 1.11672 1.11675
2 EUR/USD 20160801 00:00:00.141 1.11672 1.11677
3 EUR/USD 20160801 00:00:00.142 1.11671 1.11677
4 EUR/USD 20160801 00:00:00.143 1.11671 1.11676
5 EUR/USD 20160801 00:00:00.146 1.11672 1.11676
6 EUR/USD 20160801 00:00:00.150 1.11673 1.11677
class(EURUSD)
[1] "data.frame"
EURUSD <- EURUSD[,-1]
options(digits.secs=3)
EURUSD <- xts(EURUSD[, 2:3], order.by=as.POSIXct(EURUSD[,1], format="%Y%m%d %H:%M:%S"))
head(EURUSD)
Bid Offer
2016-08-01 1.11672 1.11675
2016-08-01 1.11672 1.11677
2016-08-01 1.11671 1.11677
2016-08-01 1.11671 1.11676
2016-08-01 1.11672 1.11676
2016-08-01 1.11673 1.11677
class(EURUSD)
[1] "xts" "zoo"
Я знаю, что эта проблема была рассмотрена в этом блоге раньше, но мне не удалось получить правильный формат даты на миллисекундах. Где я иду не так?
благодаря