I have two zoo time series with the same parameters for an area but from different platforms. These two time series have a slight shift in figures even their individual trends are correct and have overlapping dates. I will like to merge both time series into one continuous series while adjusting for errors in both series using the data for the dates that overlap. How do I do this please? I have added some sample data below.
library(ggplot2)
library(gtable)
library(grid)
library(zoo)
library(reshape)
library(reshape2)
##Create zoo objects
x<-as.zoo(as.matrix(cbind(a=1:8,b=2:9)))
y<-as.zoo(as.matrix(cbind(a=2:9,b=3:10)))
##Create dates
CCnb1<-seq(from=as.Date("2004-01-01"),to=as.Date("2004-08-01"),by="1 months")
CCnb2<-seq(from=as.Date("2004-06-01"),to=as.Date("2005-01-01"),by="1 months")
##Index appropriately
index(x)<-CCnb1
index(y)<-CCnb2
####Create dataframes
x1<-as.data.frame(x)
y1<-as.data.frame(y)
##Add date columns
x1$Date=CCnb1
y1$Date=CCnb2
##Melt data frames
x2<-melt(x1, id.vars="Date")
y2<-melt(y1, id.vars="Date")
I have included a pseudo plot using ggplot2 of how the lines might look. My actual time series are much longer and the shift in values isn't as bad as this example.
#Plot
NT<-ggplot(x2, aes(x=Date, y=value,colour=variable, group=variable)) +
theme_bw()+ geom_line(size=0.5,colour="grey30")
NTb<-NT + geom_line(data=y2,aes(x=Date, y=value,group=variable))
NTb+facet_wrap(~variable)