Hi Roy,
Your problem is occurring because S-PLUS is
changing your matrix (DATA1[ ,2]) to a vector.
This is the standard default behavior: when one
of the dimensions of a matrix or array has only one
component, that dimension is dropped. Thus when
you select one column of the matrix, the result
is changed to a vector.
To avoid this, use the 'drop = F' argument when subscripting
your matrix.
> y1 <- timeSeries(DATA1[, 2, drop = F], DATA1[, 1])
> y1
Positions USD1
04/10/2001 00:00:00.000 37.3
04/11/2001 00:00:00.000 81.2
04/12/2001 00:00:00.000 65.3
04/16/2001 00:00:00.000 91.8
04/17/2001 00:00:00.000 0.4
04/18/2001 00:00:00.000 32.6
04/19/2001 00:00:00.000 55.4
04/20/2001 00:00:00.000 65.3
04/23/2001 00:00:00.000 13.0
04/24/2001 00:00:00.000 55.0
04/25/2001 00:00:00.000 34.5
04/26/2001 00:00:00.000 38.6
>
If you are doing this subscripting in automated code,
or within a function, use the drop = F argument
(or drop = T if needed elsewhere) to explicitly control
the form of the object that results from subscripting.
Hope this helps.
A bit more detail in the example output below:
> DATA1
DATE USD1 USD2 USD3
1 04/10/2001 00:00:00.000 37.3 34.3 65.3
2 04/11/2001 00:00:00.000 81.2 20.2 62.1
3 04/12/2001 00:00:00.000 65.3 49.2 36.2
4 04/16/2001 00:00:00.000 91.8 83.4 26.8
5 04/17/2001 00:00:00.000 0.4 14.9 32.6
6 04/18/2001 00:00:00.000 32.6 74.0 56.5
7 04/19/2001 00:00:00.000 55.4 79.8 12.8
8 04/20/2001 00:00:00.000 65.3 35.6 69.8
9 04/23/2001 00:00:00.000 13.0 65.6 16.8
10 04/24/2001 00:00:00.000 55.0 19.6 50.0
11 04/25/2001 00:00:00.000 34.5 78.2 42.3
12 04/26/2001 00:00:00.000 38.6 5.6 85.4
> y1<-timeSeries(DATA1[,(2:4)],DATA1[,1])
> y1
Positions USD1 USD2 USD3
04/10/2001 00:00:00.000 37.3 34.3 65.3
04/11/2001 00:00:00.000 81.2 20.2 62.1
04/12/2001 00:00:00.000 65.3 49.2 36.2
04/16/2001 00:00:00.000 91.8 83.4 26.8
04/17/2001 00:00:00.000 0.4 14.9 32.6
04/18/2001 00:00:00.000 32.6 74.0 56.5
04/19/2001 00:00:00.000 55.4 79.8 12.8
04/20/2001 00:00:00.000 65.3 35.6 69.8
04/23/2001 00:00:00.000 13.0 65.6 16.8
04/24/2001 00:00:00.000 55.0 19.6 50.0
04/25/2001 00:00:00.000 34.5 78.2 42.3
04/26/2001 00:00:00.000 38.6 5.6 85.4
> y1<-timeSeries(DATA1[,2],DATA1[,1])
>
> y1
Positions 1
04/10/2001 00:00:00.000 37.3
04/11/2001 00:00:00.000 81.2
04/12/2001 00:00:00.000 65.3
04/16/2001 00:00:00.000 91.8
04/17/2001 00:00:00.000 0.4
04/18/2001 00:00:00.000 32.6
04/19/2001 00:00:00.000 55.4
04/20/2001 00:00:00.000 65.3
04/23/2001 00:00:00.000 13.0
04/24/2001 00:00:00.000 55.0
04/25/2001 00:00:00.000 34.5
04/26/2001 00:00:00.000 38.6
> y1 <- timeSeries(DATA1[, 2, drop = F], DATA1[, 1])
> y1
Positions USD1
04/10/2001 00:00:00.000 37.3
04/11/2001 00:00:00.000 81.2
04/12/2001 00:00:00.000 65.3
04/16/2001 00:00:00.000 91.8
04/17/2001 00:00:00.000 0.4
04/18/2001 00:00:00.000 32.6
04/19/2001 00:00:00.000 55.4
04/20/2001 00:00:00.000 65.3
04/23/2001 00:00:00.000 13.0
04/24/2001 00:00:00.000 55.0
04/25/2001 00:00:00.000 34.5
04/26/2001 00:00:00.000 38.6
>
Steven McKinney
Consulting Services
Insightful Corporation
smckinney@insightful.com <mailto:smckinney@insightful.com>
Views expressed are my own, not Insightful's, etc.
-----Original Message-----
From: Tang, Roy Haicheng (Corp Credit - NY) [mailto:RoyHaicheng_Tang@ml.com]
Sent: Thursday, April 21, 2005 8:48 AM
To: s-news@lists.biostat.wustl.edu
Subject: [S] [Q] Time series data
Hi all,
I just started to use time series in Splus and have a couple of questions on
timeSeries and seriesMerge. I have some time series data like this:
DATE USD1 USD2 USD3
4/10/2001 37.3 34.3 65.3
4/11/2001 81.2 20.2 62.1
4/12/2001 65.3 49.2 36.2
4/16/2001 91.8 83.4 26.8
4/17/2001 0.4 14.9 32.6
4/18/2001 32.6 74.0 56.5
4/19/2001 55.4 79.8 12.8
4/20/2001 65.3 35.6 69.8
4/23/2001 13.0 65.6 16.8
4/24/2001 55.0 19.6 50.0
4/25/2001 34.5 78.2 42.3
4/26/2001 38.6 5.6 85.4
...
If I read it using
y1<-timeSeries(DATA1[,(2:4)],DATA1[,1])
I get a nice timeSeries in Splus in nice form. Each time series has its name
(USD1, USD2...) attached. But if I only read 1 time series, say,
y1<-timeSeries(DATA1[,2],DATA1[,1])
The column name (or series name) becomes "1". This poses problem when I tried
to use mergeSeries to merge multiple time series, some of which have column
names and some of them only has "1" as column name (or series name). e.g.,
if TEST1 is a (multi-variate) time series with proper series names and
TEST2,TEST3 are both single time series with "1" as series name, the
following command will not work:
> TEMP_seriesMerge(TEST1,TEST2,TEST3,pos="union",how="NA")
Problem in "dimnames<-.data.frame"(x, dn): column names must be unique
Use traceback() to see the call stack
My question is: how can I add series name to the two series with "1" as
series name; or use some other approach to merge the series?
Any help is appreciated.
Thanks!
-Roy
If you are not an intended recipient of this e-mail, please notify the
sender, delete it and do not read, act upon, print, disclose, copy, retain or
redistribute it. Click here for important additional terms relating to this
e-mail. http://www.ml.com/email_terms/
|