[R] Create a zoo/xts Time Series with Millisecond jumps

Gabor Grothendieck ggrothendieck at gmail.com
Thu Mar 3 00:20:42 CET 2011


On Wed, Mar 2, 2011 at 5:14 PM, rivercode <aquanyc at gmail.com> wrote:
> Is there a easy way to create the time index for a zoo/xts object for every
> 100 milliseconds.
>
> eg.  time Index would be:
>
> 10:00:00:100
> 10:00:00:200
> 10:00:00:300
> 10:00:00:400
>
> I am looking to build an empty zoo/xts object with time index from 10am to
> 3pm, index jumps by 100ms each row.
>

Here are three ways.  as.xts(z2) could be used to turn the second one into xts.

library(zoo)
library(chron)
len <- 5 * 60 * 60 * 10 + 1

# use chron times class

z1 <- zoo(, seq(times("10:00:00"), times("15:00:00"), length = len))

# use POSIXct times

z2 <- zoo(, seq(as.POSIXct("2011-01-01 10:00:00"),
	as.POSIXct("2011-01-01 15:00:00"), length = len))

# number intervals from 1 to len

z3 <- zoo(, seq_len(len))



-- 
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com



More information about the R-help mailing list