title: R Data.Table Mode Imputation First Record By Group
body: <pre><code>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))
  </code></pre>
  
  <p>Group-P are categorical. </p>
  
  <p>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.</p>
  
  <p>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.</p>
  
  <p>In hopes of reaching a data.table solution!</p>