【发布时间】:2017-10-07 20:00:42
【问题描述】:
我正在尝试填充这样的系列。
My result ACTUAL Expected
FWK_SEQ_NBR a initial_d initial_c b c d b c d
914 9.161 131 62 0 62 69 0 62 69
915 9.087 131 0 0 53 78 0 53 78
916 8.772 131 0 0 44 140 0 44 87
917 8.698 131 0 0 0 140 0 35 96
918 7.985 131 0 69 52 139 69 96 35
919 6.985 131 0 78 63 138 78 168 0
920 7.077 131 0 140 126 138 87 247 0
921 6.651 131 0 140 126 138 96 336 0
922 6.707 131 0 139 125 138 35 364 0
逻辑
a given
b lag of d by 4
c initial c for first week thereafter (c previous row + b current - a current)
d initial d - c current
这是我使用的代码
DS1 = DS %>%
mutate(c = ifelse(FWK_SEQ_NBR == min(FWK_SEQ_NBR), intial_c, 0) ) %>%
mutate(c = lag(c) + b - a)) %>%
mutate(d = initial_d - c) %>%
mutate(d = ifelse(d<0,0,d)) %>%
mutate(b = shift(d, n=4, fill=0, type="lag"))
我没有得到正确的 c,你知道我错过了什么吗?我还附上了实际和预期输出的图像。感谢您的帮助!
Actual and Expected values Image
第二张图片 - 将产品和商店添加到列列表中
Image - Product and Store as the first two columns- please help
以下是实际代码,我还复制了预期和实际输出的图像。谢谢!
【问题讨论】:
-
很难理解你想要做什么。请编辑以提供
a、b、c、d的示例值(如果适用),然后提供您想要的输出。 -
现在更有意义了。谢谢
-
您确定,您列出的问题和操作顺序正确吗?您从
d派生b,从b和a派生c,其中b依赖于d,然后又从c派生d。这将产生递归计算问题。 -
我能够在excel中很好地实现c逻辑。对于 c 计算,我从前一行的 c 值和 b 和 a 的当前值中获取。我尝试在循环中实现 C 但没有运气。感谢您的回复。
-
你的操作顺序是什么?
a已给出。假设b在c和c在d之前计算是否公平?你能分享一下b和d的R代码吗?
标签: r generate-series