To answer your first question, use seriesData() to extract the vector or
matrix of data from a timeSeries or signalSeries object.
To combine colums of multiple timeSeries, use the function seriesMerge():
> A <- timeSeries(1:3, pos=1:3)
> B <- timeSeries(cbind(B1=4:6, B2=7:9), pos=1:3)
> A
Positions 1
1960/01/02 1
1960/01/03 2
1960/01/04 3
> B
Positions B1 B2
1960/01/02 4 7
1960/01/03 5 8
1960/01/04 6 9
> seriesData(A)
[1] 1 2 3
> seriesMerge(A, B)
Positions 1 B1 B2
1960/01/02 1 4 7
1960/01/03 2 5 8
1960/01/04 3 6 9
> X <- seriesMerge(A, B)
> colIds(seriesData(X))[1] <- "A"
> X
Positions A B1 B2
1960/01/02 1 4 7
1960/01/03 2 5 8
1960/01/04 3 6 9
>
Chen,Sichong wrote:
Dear Users
I have a silly question. How can I change a Time Series vector or matrix
into a non-Time Series vector or matrix?
My problem is that I have one time series vector*** A* (280*1) and one
time series matrix*** B* (280*3), which has the same time period. What I
want to do is to combine these two together and create a new matrix
(280*4) like/// rbind///// for the no-time series dataframe. Since///
rbind///// does not work for time series data, I tried to use*** B[,4] =
A****,* but fails if it is, which says “///Problem in x[, j] <- value:
Array subscript (2) out of bounds, should be at most 1////”/. So I want
to convert A, B back to non-time series object, combine and convert again.
Do you have some idea what’s going wrong in my problem. I though it
should not be that difficult and complicated to add one more column to a
time series object.
Many thanks,
Sichong
SPlus 7.0 & FinMetrics 2.0 User
Windows XP
|