Reputation: 15002
Is it possible to add two time series data with same time frame as a single data frame.
ibrary("quantmod")
startDate = as.Date("2016-03-01")
goo= getSymbols("GOOG",from=startDate, auto.assign=F)
yoo= getSymbols("IBM",from=startDate, auto.assign=F)
dim(goo)
[1] 28 6
dim(yoo)
[1] 28 6
foo=merge(goo,yoo)
dim(foo)
[1] 28 12
#expected rows and columns 56 6
Here two stock OHLC price details are available and I want to save the OHLC price of two stock in a single data frame. I tried using merge function but it adds OHLC of two stock as separate columns. I want to concatenate corresponding OHLC price and volume of two stocks in same column
eg googles and IBM close price in single column
I also tried to covert xts to a dataframe and them merge
a=data.frame(goo)
b=data.frame(yoo)
c=merge(a,b)
dim(c)
[1] 784 12
what is the best way to concatenate this data
Upvotes: 0
Views: 784
Reputation: 1102
foo <-append(goo,yoo)
You might want to change column headers and give a column indicating the source "GOOG" or "IBM" before doing this.
goo$source <-"GOOG"
you$source <-"IBM"
names(goo) <-c("Open","High","Low","Close","Volumn","Adjusted")
names(yoo) <-c("Open","High","Low","Close","Volumn","Adjusted")
foo<-append(goo,yoo)
Upvotes: 1