I have some longitiudinal data, meaning that each individual has more than one row in the data frame. Now the idea is, to extend the data frame, so that each individual has the same number of observations and the number is a fixed constant.
To be concrete, I provided a small example:
ID <- c(1,1,1,1,2,2,2,2,2,3,3,3,4,4,4,4,4)
week <- c(1,5,10,15, 1,2,7,12,13, 1, 2,10, 1,10,11,12,13)
value <- c(2,2,5,3,10,8,5,1,3,12,12,10,6,8,2,14,9)
sim_dat <- data.frame(ID, week, value)
Now, imagine that the fixed number of observations is 15 weeks. Than I would like to have 15 rows per individual, so that the column "week" has each value between 1 and 15 for each individual. If an individual have a measurement (column "value") at a specific week, the value should be present in the corresponding line - otherwise "NA" should occur in the "value"-column.
To be more precise: ID 1 has observations at week 1,5,10 and 15 with corresponding values 2,2,5 and 3. In the end, ID 1 should have observations at week 1-15 with "NA" n the "value"-column for weeks 2,3,4,6,7,8,9,11,12,13 and 14.
I'm happy for any idea and I appreciate any kind of feedback :) Thank you