多列的同比增长率基于唯一 ID 和连续几年
我有一个数据集,其中有唯一的提案 ID、申请年份和申请年份。财务报表年度。一个提案 ID 应具有一个申请年份(t) &可以有 t-1 和(或)t-2 财政年度报表。我有多个关于债务、股权、净资产等的栏目。想要有两列用于同比增长 -F1 和 F1同比增长-2。
数据集:
Proposal ID Application Year Financial statement year Net sales
P1 2019 2019 100
P1 2019 2018 120
P1 2019 2017 130
现在,根据每个提案 ID,我需要根据我的申请年度所需的输出来了解财务报表年份之间的增长率的附加列
:
Proposal ID Application Year Financial statement year Net sales YOY - netsales-g1
P1 2019 2019 100 (100-120)/120...
P1 2019 2018 120
P1 2019 2017 130
我需要对我拥有的所有列执行相同的步骤。
我想要的是一个函数——对于每个提案 ID,它会估计 YOY 增长和增长情况。取出最新的申请日期作为最后一行,列作为数据集中所有数值变量的同比增长情况
提前感谢您的帮助! :)
I have a data set where I have a unique proposal ID, application year & financial statement year. One proposal ID shall have one application year(t) & could have t-1 &(or) t-2 financial year statements. I have multiple columns for debt, equity, networth etc & want to have two columns for YOY growth -F1 & YOY growth-2.
dataset :
Proposal ID Application Year Financial statement year Net sales
P1 2019 2019 100
P1 2019 2018 120
P1 2019 2017 130
Now basis each proposal ID I need additional columns on growth rates between financial statement years against my application year
desired output :
Proposal ID Application Year Financial statement year Net sales YOY - netsales-g1
P1 2019 2019 100 (100-120)/120...
P1 2019 2018 120
P1 2019 2017 130
this same step I need to do for all columns I have.
What I want is a function -- for each proposal ID it estimates the YOY growth & take out the latest application date as the final row with columns as YOY growth for all numeric variables in dataset
Thank you in advance for the help! :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不确定,但这是你需要的吗?
I am not sure but is it what you need?
这可以使用
mutate()
中的dplyr::lead()
公式来完成。jantior::clean_names()
是可选的,以使代码编写更容易。This can be done use the
dplyr::lead()
formula inmutate()
. Thejantior::clean_names()
is optional to make the code writing easier.