[R-SIG-Finance] merge with two time series

Gabor Grothendieck ggrothendieck at gmail.com
Sun Jan 13 04:06:16 CET 2008


These are not time series in the strict sense since they lack unique times
but you can do this with data frames:

> Lines1 <- " x1            x2
+ 2003-01-02      12           200
+ 2003-01-02      13           300
+ 2003-01-02      14           400
+ 2003-01-03      12           150
+ 2003-01-03      13           170
+ 2003-01-03      14           190
+ "
>
> Lines2 <- " y1
+ 2003-01-02       1000
+ 2003-01-03       1500
+ "
>
> DF1 <- read.table(textConnection(Lines1), skip = 1, col.names = c("Date", "x1", "x2"), colClasses = c("Date", "numeric", "numeric"))
> DF2 <- read.table(textConnection(Lines2), skip = 1, col.names = c("Date", "y"), colClasses = c("Date", "numeric"))
> merge(DF1, DF2)
        Date x1  x2    y
1 2003-01-02 12 200 1000
2 2003-01-02 13 300 1000
3 2003-01-02 14 400 1000
4 2003-01-03 12 150 1500
5 2003-01-03 13 170 1500
6 2003-01-03 14 190 1500

On Jan 12, 2008 9:23 PM, ShyhWeir Tzang <swtzang at gmail.com> wrote:
> Dear all:
>
> I have two time series x and y. x is the time series data with several
> data columns:
>                         x1            x2
> 2003-01-02      12           200
> 2003-01-02      13           300
> 2003-01-02      14           400
> 2003-01-03      12           150
> 2003-01-03      13           170
> 2003-01-03      14           190
> ....................
>
> y is  the time series data with uniqe date stamp
>                           y1
> 2003-01-02       1000
> 2003-01-03       1500
> .............
>
> I would like to have the following with merge or other commands available:
>                          x1            x2             y1
> 2003-01-02      12           200            1000
> 2003-01-02      13           300            1000
> 2003-01-02      14           400            1000
> 2003-01-03      12           150            1500
>  2003-01-03      13           170            1500
>  2003-01-03      14           190            1500
> ......................
>



More information about the R-SIG-Finance mailing list