Hi all,

 

I've been experimenting on tseries package, namely ts class and I've
been having to do a workaround to have time indexing. I was wondering if
there's an easier way.  I am working with monthly data. i.e. I would
like to be able to use yearmon class easily.

 

Say I have a bunch of time series with different intervals but they have
overlapping time frame.

 

If I wanted to loop through them relative to some timepoint, I would
either have to translate the time into an index, and do the
corresponding arithmetic to calculate what that would correspond to in
another time series.

 

The alternate way would be to find the index by matching the time, but
that doesn't work so well as match doesn't always come up due to
numerical precision issues.

 

ts1 = ts(1:10, start = c(2000,1), frequency = 12)

specialtime = time(ts1)[ts1==5]

 

ts2 = ts(1:20, start = c(2000,8), frequency = 12)

 

 

    for( i in 1:match(specialtime, time(ts2)))

                                ts2[i] = ...

 

 

so what I end up doing is within the loop, or wherever I need to set a
value, I end up doing:

 

match(yearmon(specialtime), yearmon(time(ts2)))

 

Somehow, that seems unusually unwieldly as compared to being directly
able to index via time.

 

So I've also tried xts with time index, however, the time index needs to
be in ISO format whereas the times that I have is like variable
specialtime where it's of the form 2005.3

 

I tried converting all of the variables into xts, I also tried changing
the indexing class into yearmon 

Ts3 = convertIndex(as.xts(ts2), "yearmon")

 

Now I can do aa = time(Ts3)[1] and it is an yearmon class, 

 

however, I still can't access anything using Ts3[aa]. It gives me:

 

Error in as.POSIXlt.character(x, tz, ...) : 

  character string is not in a standard unambiguous format

 

So I'm not sure if I'm missing something obvious, if anyone could help?

 

Thanks,

 

Ivan Zhang


	[[alternative HTML version deleted]]

