[R] Loading intraday data with zoo
arun
smartpink111 at yahoo.com
Mon May 20 17:21:16 CEST 2013
Hi,
You may need to add "dec=","" in the read.csv.
dat1<- read.table(text="
Time;Mid
31/01/2013 00:00;1,35679
31/01/2013 00:01;1,35678
31/01/2013 00:02;1,356785
31/01/2013 00:03;1,35689
31/01/2013 00:04;1,3569
31/01/2013 00:05;1,3569
31/01/2013 00:06;1,356885
31/01/2013 00:07;1,35691
31/01/2013 00:08;1,357
",sep=";",dec=",",header=TRUE,stringsAsFactors=FALSE)
f1 <- function(...) as.POSIXct(paste(...), format = "%d/%m/%Y %H:%M")
library(zoo)
b <- read.zoo(dat1, index = 1, FUN = f1)
library(xts)
dat2<- xts(b)
dat2
# x
#2013-01-31 00:00:00 1.356790
#2013-01-31 00:01:00 1.356780
#2013-01-31 00:02:00 1.356785
#2013-01-31 00:03:00 1.356890
#2013-01-31 00:04:00 1.356900
#2013-01-31 00:05:00 1.356900
#2013-01-31 00:06:00 1.356885
#2013-01-31 00:07:00 1.356910
#2013-01-31 00:08:00 1.357000
plot(dat2)
A.K.
>Hi all,
>
>I would like to do some time series analysis on intraday data.
>Therefore, I try to read some data with zoo and then convert them a xts-object.
>
>The data are like:
>Time;Mid
>31/01/2013 00:00;1,35679
>31/01/2013 00:01;1,35678
>31/01/2013 00:02;1,356785
>31/01/2013 00:03;1,35689
>31/01/2013 00:04;1,3569
>31/01/2013 00:05;1,3569
>31/01/2013 00:06;1,356885
>31/01/2013 00:07;1,35691
>31/01/2013 00:08;1,357
>
>My r-code is
>df<-read.csv("file.csv", header=TRUE, sep=";")
>f1 <- function(...) as.POSIXct(paste(...), format = "%d/%m/%Y %H:%M")
>b <- read.zoo(df, index = 1, sep=";", header = TRUE, FUN = f1)
>data<-xts(b)
>plot(data)
>
>The following error occurs:
>Error in plot.window(...) : need finite 'ylim' values
>In addition: Warning messages:
>1: In as.double.xts(y) : NAs introduced by coercion
>2: In min(x) : no non-missing arguments to min; returning Inf
>3: In max(x) : no non-missing arguments to max; returning -Inf
>
>I think the problem is that the index does not recognize the
"%d/%m/%Y %H:%M" format, but I do not know how to handle this problem.
>Does anyone know a solution to my problem?
Thank you a lot!
Michi
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Intraday.pdf
Type: application/pdf
Size: 4762 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20130520/215c0426/attachment.pdf>
More information about the R-help
mailing list