【发布时间】:2018-05-23 07:54:31
【问题描述】:
我需要将输出存储到一个单独的向量中,以便我可以绘制数据(years 与 reproduction_rate)。目前它只存储最后一年而不是年份 1:20。有没有办法使用 grep/regex 将输出值存储到一个外部向量中,而不是从控制台复制和粘贴?
N <- 1000
years <- 1:20
storage <- ()
for (year in years) {
reproduction_rate <- rnorm(n=1, mean=1, sd=0.4)+N
phrase <- paste("In year", year, "the population rate was", reproduction_rate)
print(paste("In year", year, "the population rate was", reproduction_rate))
storage <- (reproduction_rate)
}
【问题讨论】: