Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/77.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 组合不等数据帧并应用计算_R_Dataframe_Forecasting - Fatal编程技术网

R 组合不等数据帧并应用计算

R 组合不等数据帧并应用计算,r,dataframe,forecasting,R,Dataframe,Forecasting,我一直在做一些数据清理和回归,但现在我想应用输出,然而,我被困在以下问题上 一个称为“历史”的数据框,如下所示: Year Value 2014 5 2015 7.5 2016 11 另一个数据框称为“预测”,如下所示(未来的新年): 等 因此,我希望有一个数据框来显示2017年开始的历史值和预测值(11*1.05) 我该怎么办 非常感谢 a <- read.table(header=T, text="Year Value 2014 5 2015 7.5 2016

我一直在做一些数据清理和回归,但现在我想应用输出,然而,我被困在以下问题上

一个称为“历史”的数据框,如下所示:

Year  Value
2014   5
2015   7.5
2016   11
另一个数据框称为“预测”,如下所示(未来的新年):

因此,我希望有一个数据框来显示2017年开始的历史值和预测值(11*1.05)

我该怎么办

非常感谢

a <- read.table(header=T, text="Year  Value
2014   5
2015   7.5
2016   11")
b <- read.table(header=T, text="
Year  Growth
2017   0.05
2018   0.11")
a <- read.table(header=T, text="Year  Value
2014   5
2015   7.5
2016   11")
b <- read.table(header=T, text="
Year  Growth
2017   0.05
2018   0.11")
rbind(a, cbind(
  Year=b$Year, 
  Value=cumprod(c(tail(a$Value, 1), 1+b$Growth))[-1])
)
#   Year   Value
# 1 2014  5.0000
# 2 2015  7.5000
# 3 2016 11.0000
# 4 2017 11.5500
# 5 2018 12.8205