data=data.frame("StudentID"=c(1,1,1,1,1,2,2,2,2,2,3,3,3,3,3,4,4,4,4,4),
"Time"=c(1,2,3,4,5,1,2,3,4,5,1,2,3,4,5,1,2,3,4,5),
"Group"=c(1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0),
"Class"=c(1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1),
"Test"=c(NA,1,0,NA,1,1,1,1,0,0,1,0,1,0,1,1,1,0,0,0),
"Score"=c(0,1,1,0,1,NA,0,1,NA,0,NA,1,1,1,1,0,0,1,1,1),
"P"=c(NA,3,1,1,1,1,2,NA,3,1,3,3,2,2,2,NA,NA,1,2,2))
Group-P are categorical.
data1: I wish to calculate the modes of Test, Score, and P separately by Group and Class and then impute the modes for only Time = 1.
data2: As a separate step I wish to create data2; data2 takes data1 and for any missing values at Time T where T > 1, copy down the value above for each group for the variables Test and Score.
In hopes of reaching a data.table solution!