[R-SIG-Finance] merging tseries with a table

aschmid1 aschmid1 at stevens.edu
Tue Sep 29 18:08:42 CEST 2015


Thank you Joshua, this worked well.
And I agree with Brian Peterson: it's time to use quantmod - if only I 
had enough time for that... :)
Alec

On 09/29/2015 11:07 AM, Joshua Ulrich wrote:
> On Tue, Sep 29, 2015 at 9:39 AM, aschmid1 <aschmid1 at stevens.edu> wrote:
>> I'm trying to merge prices obtained with get.hist.quote():
>>> 
>>> head(mkt_prc)
>> 
>>            AdjClose
>> 2009-01-02 36.21114
>> 2009-01-05 36.04547
>> 2009-01-06 36.42040
>> 2009-01-07 35.34793
>> 2009-01-08 35.40897
>> 2009-01-09 34.67655
>> 
>> with data from a csv table:
>>> 
>>> head(gdp_tab)
>> 
>>        Date Actual
>> 1 1/31/2001    1.4
>> 2 2/28/2001    1.1
>> 3 3/29/2001    1.0
>> 4 4/27/2001    2.0
>> 5 5/25/2001    1.3
>> 6 6/29/2001    1.2
>> 
>> I use command (as far as my imagination goes):
>>  x<-merge(gdp_tab, mkt_prc, by.x="Date", by.y=index(mkt_prc))
>> 
>> and it gives me an error:
>> Error in fix.by(by.y, y) : 'by' must match numbers of columns
>> 
>> Any suggestions on how to do this?
> 
> Convert gdp_tab to zoo before you merge.
> 
> gdp_tab <- read.table(text="Date Actual
> 1/31/2001 1.4
> 2/28/2001 1.1
> 3/29/2001 1.0
> 4/27/2001 2.0
> 5/25/2001 1.3
> 6/29/2001 1.2", header=TRUE, as.is=TRUE)
> library(zoo)
> z <- zoo(gdp_tab$Actual, as.Date(gdp_tab$Date, "%m/%d/%Y"))
> mkt_prc <- tseries::get.hist.quote("SPY")
> x <- merge(mkt_prc, z)
> 
>> Thanks! Alec
>> 
>> _______________________________________________
>> R-SIG-Finance at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
>> -- Subscriber-posting only. If you want to post, subscribe first.
>> -- Also note that this is not the r-help list where general R 
>> questions
>> should go.



More information about the R-SIG-Finance mailing list