Skip to content

Zoo Data

2 messages · arun, Joshua Ulrich

#
HI Jakob,

If your data is based on 30 min interval, this should work:

dat1<-read.table(text=" 
TIME, Value1, Value2 
01.08.2011 02:30:00, 4.4, 4.7 
01.09.2011 03:00:00, 4.2, 4.3 
01.11.2011 01:00:00, 3.5, 4.3 
01.12.2011 01:40:00, 3.4, 4.5 
01.01.2012 02:00:00, 4.8, 5.3 
01.02.2012 02:30:00, 4.9, 5.2 
01.08.2012 02:30:00, 4.1, 4.7 
01.12.2012 03:00:00, 4.7, 4.3 
01.01.2013 01:00:00, 3, 4.3 
01.01.2013 01:30:00, 3.8, 4.1 
01.01.2013 02:00:00, 3.8, 4.3 
01.01.2013 02:30:00, 3.9, 4.2 
01.01.2013 03:00:00, 3.7, 4.5 
01.01.2013 03:30:00, 3.5, 4.1 
01.02.2013 02:00:00, 3.8, 4.3
02.02.2013 04:30:00, 3.9, 4.2
",sep=",",header=TRUE,stringsAsFactors=FALSE)?? 
dat1$TIME<-as.POSIXct(dat1$TIME,format="%d.%m.%Y %H:%M:%S")

library(zoo) 
z1<- zoo(dat1[,-1],dat1[,1])

Vec<-format(seq(from=as.POSIXct("2012-01-01 02:30:00", format="%Y-%m-%d %H:%M:%S"),length.out=3, by="30 min"),"%H:%M:%S")
z1[format(time(z1),"%H:%M:%S")%in% Vec,]
#??????????????????? Value1 Value2
#2011-08-01 02:30:00??? 4.4??? 4.7
#2011-09-01 03:00:00??? 4.2??? 4.3
#2012-02-01 02:30:00??? 4.9??? 5.2
#2012-08-01 02:30:00??? 4.1??? 4.7
#2012-12-01 03:00:00??? 4.7??? 4.3
#2013-01-01 02:30:00??? 3.9??? 4.2
#2013-01-01 03:00:00??? 3.7??? 4.5
#2013-01-01 03:30:00??? 3.5??? 4.1
A.K.




----- Original Message -----
From: Jakob Hahn <Jakob.Hahn at stud.hs-esslingen.de>
To: arun <smartpink111 at yahoo.com>
Cc: 
Sent: Saturday, March 9, 2013 10:04 AM
Subject: Re: Zoo Data

Hi Arun,

z1[seq(which(time(z1)==as.POSIXct("**.**.2012 02:30:00",format="%d.%m.%Y %H:%M:%S")),which(time(z1)==as.POSIXct("**.**.2012 03:30:00",format="%d.%m.%Y %H:%M:%S"))),]

Is there a possibility to get all data e.g between two times - not depending on a special date - all values betweend 2:30 and 3:30?
Thanks
Jakob


---

Am 08.03.2013 um 22:05 schrieb arun:
3 days later
#
It's much easier to use xts' time-of-day subsetting:

library(xts)
dat1 <- as.xts(read.zoo(text="TIME, Value1, Value2
01.08.2011 02:30:00, 4.4, 4.7
01.09.2011 03:00:00, 4.2, 4.3
01.11.2011 01:00:00, 3.5, 4.3
01.12.2011 01:40:00, 3.4, 4.5
01.01.2012 02:00:00, 4.8, 5.3
01.02.2012 02:30:00, 4.9, 5.2
01.08.2012 02:30:00, 4.1, 4.7
01.12.2012 03:00:00, 4.7, 4.3
01.01.2013 01:00:00, 3, 4.3
01.01.2013 01:30:00, 3.8, 4.1
01.01.2013 02:00:00, 3.8, 4.3
01.01.2013 02:30:00, 3.9, 4.2
01.01.2013 03:00:00, 3.7, 4.5
01.01.2013 03:30:00, 3.5, 4.1
01.02.2013 02:00:00, 3.8, 4.3
02.02.2013 04:30:00, 3.9, 4.2",
sep=",", header=TRUE, FUN=as.POSIXct, format="%d.%m.%Y %H:%M:%S"))

dat1["T02:30/T03:00"]

Best,
--
Joshua Ulrich  |  about.me/joshuaulrich
FOSS Trading  |  www.fosstrading.com

R/Finance 2013: Applied Finance with R  | www.RinFinance.com
On Sat, Mar 9, 2013 at 11:59 AM, arun <smartpink111 at yahoo.com> wrote: