Let us assume that weight has been measured on 624 patients for 4 distinct time points: M0, M1, M3 and M6
``` {r}
library(zoo)
#start by creating the vectors which includes the variables we want to use for imputation
WeightImpute<-cbind(MetSData$POIDS_M0,MetSData$POIDS_M1,MetSData$POIDS_M3,MetSData$POIDS_M6)
#then we rename the columns
colnames(WeightImpute)=c("w0", "w1",
"w3", "w6")
#creating a replicate array to be used within the for loop
WeightImputeF=WeightImpute
#creating an object which is equal to the number of rows within our array (624)
n=dim(WeightImpute)[1]
#creating a counter (1:624) labeling it index
index=which(!is.na(WeightImpute[,1]))
#creating a for loop using the na.locf function from library (zoo) that will carry on the LOCF. ATTENTION: the imputation will be carry out by column, that is the `i' is placed in the row part of the argument
for(i in index){WeightImputeF[i,]=na.locf(WeightImpute[i,])}
WeightImputeF
```