Good afternoon I am not an R user, but I need to get the difference between the first date and last date within RFID, to create a new column X. Therefore, the first value needs to be 1 (not zero), the second 2, ..., n.
Here an example of the data.
Thanks in advance.
RFID visit_date ADFI location
985152014315936 2017-11-25 2133 16
985152014315936 2017-11-26 2186 16
985152014315936 2017-11-27 3489 16
985152014315936 2017-11-28 2432 16
985152014315937 2017-11-24 15 17
985152014315937 2017-11-25 1512 17
985152014315937 2017-11-26 2378 17
985152014315937 2017-11-27 3241 17
985152014315938 2017-11-24 584 17
985152014315938 2017-11-25 1689 17
985152014315938 2017-11-26 2807 17
985152014315938 2017-11-27 2369 17
985152014315938 2017-11-28 2576 17
985152014315939 2017-11-25 1084 17
985152014315939 2017-11-26 3489 17
985152014315939 2017-11-27 2630 17
985152014315939 2017-11-28 3585 17
985152014315939 2017-11-29 3433 17
985152014315939 2017-11-30 2962 17
Here is a solution using
dplyr
andlubridate
:Sample data
Using data.table:
of if you want to add 1: