考虑以下情节:
x <- seq(from = 1.01, to = 1.05, by = 0.01) ## test
pmt_test = data.frame(Amount = c(paste(0.01, sep = " * "), paste(0.02, "r", sep = " * ")), Start = c(2,4), End = c(4,4))
p = paste("(", pmt_test$Amount, " * (i %in% ", pmt_test$Start, ":", pmt_test$End, "))", collapse = " + ")
res = Reduce(function(r, i) { (r + eval(parse(text = p))) * x[i] }, seq_along(x), init = 100, accumulate = TRUE)[-1]
par(xaxs='i',yaxs='i')
plot(res, type = "l", xaxt = 'n')
x.labels = paste("Year", 0:4, sep=" ")
axis(1, at = 0:4, labels=x.labels)
我获得的情节从第 1 年开始并延伸到第 4 年之后。我正在寻找的预期图表应该从第 0 年开始并在第 4 年结束。似乎数据发生了变化并且没有从正确的点开始为 x 轴。
有什么办法解决吗?谢谢!