在R中添加斜坡函数 [英] Adding a ramp function in R

查看:58
本文介绍了在R中添加斜坡函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一个生产工厂中有多个团队.生产工厂中的一个团队可以充分发挥潜力生产12种产品,但一个团队要完全发挥潜力需要12个月的时间.目前,我们有100个团队.如果我们每个月增加一个团队,这就是它的外观.对于每个团队,生产率应该每月增加1/12,并在12个月后保持不变.

There are multiple teams in a production plant. A team in a production plant can produce 12 products at the full potential but it takes 12 months for a team to reach full potential.At current we have 100 teams. If we add a team each month, this is how it should look.For each team the productivity should increase by 1/12 per month and stay constant after 12 months.

Month       Teams        Teams_Equivalent      
Jan-20       101           100.08                 
Feb-20       102           100.25                 
Mar-20       103           100.50                 
Apr-20       104           100.83                 
May-20       105           101.25                 
Jun-20       106           101.75                 
Jul-20       107           102.33                 
Aug-20       108           103.00                 
Sep-20       109           103.75                 
Oct-20       110           104.58                 
Nov-20       111           105.50                 
Dec -20      112           106.50                 
Jan-21       113           107.50                     
Feb-21       114           108.50                 

我尝试使用for循环,如下所示,但它不起作用,

I tried to use for loop, something like below and it's not working,

a = 1:14
Teams <- 100
for (i in seq_along(a)) {
  Teams_Equivalent = Teams_Equivalent*(1/12)
}
print(Teams_Equivalent)

感谢您的任何帮助.

推荐答案

我不确定我是否正确理解了您的意思,但这给出了您的要求,

I am not sure if I understand you correctly but this gives what you are asking,

a <- 1:14
first_step <-round(cumsum(1:12)/12 +100,2)


for(i in 13:max(a)) {

    first_step[i] <- max(first_step) +1
}

[1] 100.08 100.25 100.50 100.83 101.25 101.75 102.33 103.00 103.75
[10] 104.58 105.50 106.50 107.50 108.50

这篇关于在R中添加斜坡函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆