需更换的物品数量错误不是替换长度的倍数

时间:2019-03-28 10:54:26

标签: r

我有if ... else函数来替换28个周期的生存率值,我认为它会停止替换第2行之后的任何值。结果,“要替换的项目数不是替换长度的倍数”。

Survival.rate[nperiod, ] = Survival.rate[nperiod - 1,] * Retention.Rate           
  

annual.profit [nperiod,] = Annual.profit *中的错误   Survival.rate [nperiod,:要替换的项目数不是   替换长度的倍数

nperiods = 28   
Survival.rate = matrix(0, nrow=nperiods, ncol=5)
annual.profit = matrix(0, nrow=nperiods, ncol=5)
dis.annual.profit = matrix(0, nrow=nperiods, ncol=5)

for (nperiod in 1:nperiods) {

  if (nperiod==1) {

    Survival.rate[nperiod, ] = 1
    # calculate annual profit for year.one
    annual.profit[nperiod, ] = Annual.Margin-Acquisition.Cost

  } 
  else {

    Survival.rate[nperiod, ] = Survival.rate[nperiod - 1,] * Retention.Rate 

    annual.profit[nperiod, ] = annual.profit * Survival.rate[nperiod, ]

  }
  dis.annual.profit[nperiod, ] =  annual.profit[
    nperiod, ] / (1+interest.rate)^(nperiod)

}`

0 个答案:

没有答案