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():
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:
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)