[R] Semi-Regular Time Series with Missing Values

Gabor Grothendieck ggrothendieck at gmail.com
Wed Jan 19 05:06:36 CET 2011


On Tue, Jan 18, 2011 at 6:33 PM, Adam Oliner <oliner at gmail.com> wrote:
> Hi,
>
> I'm trying to make a ts object that has both NA values and a frequency other
> than 1 (so I can use stl). I've tried all permutations I can think of, but
> cannot get the desired (expected?) results.
>
> The values live in x and the corresponding semi-regular time stamps are in
> t:
>
>> library('zoo')
>> z = zoo(x, order.by=t, frequency=24)
>> zzr = as.zooreg(z, start=0)
>> zr = zooreg(x, order.by=t, start=0, frequency=24)
>> zrz = as.zoo(zr)
>
> The objects z, zr, and zzr all have frequency 24, as desired, and plot
> correctly. Object zrz plots correctly but has frequency 1. Now I try to make
> it a ts object:
>
>> zrt = ts(zzr)
> ... omits the missing values.
>> zrt = ts(zzr, frequency=24)
> ... omits the missing values and changes the timestamps.
>> plot(ts(zr))
> ... omits the missing values.
>> zrt = ts(zr, frequency=24)
> ... omits the missing values and changes the timestamps.
>> zrt = as.ts(zr)
> ... inserts 23 NA values between each legitimate value.
>> zrt = as.ts(zr, frequency=24)
> ... inserts 23 NA values between each legitimate value.
>> zrzt = ts(zrz)
> ... omits the missing values.
>> zrzt = ts(zrz, frequency=24)
> ... omits the missing values and changes the timestamps.
>

Note that there is an as.ts.zoo method.


-- 
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