首页 > 解决方案 > 如何在 Rstudio 中组合两个时间序列?

问题描述

代码:

times_USST <- ts(Final_Com_return$Comp.int_USST, start= 1934-01, frequency = 12)
times_TRSB <- ts(Final_Com_return$Comp.int_TRSB, start= 1934-01, frequency= 12)

这两行代码组成了两个独立的情节。我的问题是将两者结合起来。我们正在尝试为股票指数和我们的国库券制作线性和对数比例图

标签: rggplot2plot

解决方案


我认为这个帖子。会帮助你。正如Pete Baker所述, “您可以使用 xts 包来为您处理细节(例如,即使该系列有间隙)”

library(xts)
ts1<-as.xts(ts(c(1:12),star=c(2014,1),freq=12))
ts2<-as.xts(ts(c(13:24),star=c(2015,1),freq=12))
str(ts3 <- c(ts1, ts2))
# An ‘xts’ object on Jan 2014/Dec 2015 containing:
# Data: int [1:24, 1] 1 2 3 4 5 6 7 8 9 10 ...
# Indexed by objects of class: [yearmon] TZ: 
# xts Attributes:
# NULL

推荐阅读