根据r纵向数据的日期创建虚拟变量
我在R中有纵向患者数据。我想创建新的_Dummy变量,就像我在下表中所示。如果consultation_date变量小于registration_date变量,则我希望dummy_varia -varia -varia -varia -variable值为0,如果咨询_date变量大于registration_date变量,则为1。
patid | Consultation_date | registration_date | new_dummy |
---|---|---|---|
1 | 07/07/2016 | 07/07/2018 | 0 |
1 | 07/07/07/2019 | 07/07/07/2018 | 1 |
2 | 14/08/08/2016 | 07/09/2016 07/09/2016 | 0 |
3 | 07/05/2015/2015 | 19/02/02/02/02/02/02/02/02/02/ 2016 | 0 |
3 | 02/12/2016 | 19/02/2016 | 1 |
I have longitudinal patient data in R. I would like to create the new_dummy variable just like I demonstrated in the table below. I would like the dummy_variable value to be 0 if the consultation_date variable is smaller than the registration_date variable and to be 1 if the consultation_date variable is bigger than the registration_date variable.
patid | consultation_date | registration_date | new_dummy |
---|---|---|---|
1 | 07/07/2016 | 07/07/2018 | 0 |
1 | 07/07/2019 | 07/07/2018 | 1 |
2 | 14/08/2016 | 07/09/2016 | 0 |
3 | 07/05/2015 | 19/02/2016 | 0 |
3 | 02/12/2016 | 19/02/2016 | 1 |
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您的列在正确的类(
date
)中,则可以简单地以正确的格式转换它们,它是:(
感谢@akrun的日期格式)
If your columns are in the right class (
Date
), you can simply useTo convert them in the right format, it's:
(thanks @akrun for the date format)