# [R] Building a time series.

rkevinburton at charter.net rkevinburton at charter.net
Thu Sep 4 23:16:06 CEST 2008

```I have a need to build a time series and there are a couple of aspects about the time series object that are confusing me. First it seems that ts.union is not doing what I would expect. For example:

x0 <- rep(0,10)
x1 <- rep(1,10)

xt0 <- ts(x0, frequency=10)
xt1 <- ts(x1, frequency=10)

st2 <- ts.union(xt0, xt1)
> xt2
Time Series:
Start = c(1, 1)
End = c(1, 10)
Frequency = 10
xt0 xt1
1.0   0   1
1.1   0   1
1.2   0   1
1.3   0   1
1.4   0   1
1.5   0   1
1.6   0   1
1.7   0   1
1.8   0   1
1.9   0   1

> spectrum(xt2)
Error in plot.window(...) : need finite 'ylim' values
1: In xy.coords(x, y, xlabel, ylabel, log = log) :
10 y values <= 0 omitted from logarithmic plot
2: In min(x) : no non-missing arguments to min; returning Inf
3: In max(x) : no non-missing arguments to max; returning -Inf
4: In xy.coords(x, y, xlabel, ylabel, log) :
5 y values <= 0 omitted from logarithmic plot

I would expect that ts.union would concatenate the time series. I would expect xt2 from above to be a time series from 1:20. If I do

xt2 <- c(xt0, xt1)

> xt2
[1] 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1
>

This seems to get rid of the time series nature of each of the objects.

I can do:

> xt2 <- ts(c(xt0,xt1), frequency=10)
> xt2
Time Series:
Start = c(1, 1)
End = c(2, 10)
Frequency = 10
[1] 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1
>

But whst am I to interpret the start and end (c(1,1), and c(2,10)) to be?

Is this the best way to concatenate two time series?

Thank you.

Kevin

```