The dataframe I am working with has two columns: 1) person ID and 2) date. I am trying to assign numeric day values of date for each person.
For instance, person 1 has date from 2016-01-01 (baseline) to 2016-01-05 (last date for person 1). I want to create a day column that would translate this to 1, 2, 3, 4, 5. If person 2 has date from 2016-01-13 to 2016-01-16, the day column for person 2 would be 1, 2, 3, 4.
df <- for(i in length(unique(per1$date))){df$day[per1$date[1] + i] <- i+1}
This is basically what I am trying to do, but I get an error message saying:
"replacement has 17119 rows, data has 1670"
Please let me know how I can write the code for this. Thank you.