我有一个数据框(02个结果/输血日期),其中有一系列如下所示的日期:
2020-03-28 18:01:00
2020-03-28 22:16:00
2020-04-01 19:30:00
2020-04-01 23:56:00
我想为每个人分配唯一的ID,如下所示:
1 2020-03-28 18:01:00
2 2020-03-28 22:16:00
3 2020-04-01 19:30:00
4 2020-04-01 23:56:00
值需要按时间顺序递增。
附带说明一下,当我使用dput函数查看数据时,它看起来像这样吗? 1588635000、1588706160、1588714320、1588721640、1588881900
I found a thread that seems to be similar but cannot seem to make these solutions work: Create an ID (row number) column
提前致谢
We can use
data.table
arrange the data by
transfusion_date
and then you can create a unique index for each row.在基数R中,您可以执行以下操作:
Or using
dplyr
:您可以使用dplyr