I would like to populate the next two NA rows (and only the next two rows) of the variable "value" in a dataframe "df", grouped by individual. I tried with na.locf (using tidyr/dplyr packages) but did not manage to populate only the next two rows.
Dataframe:
library(data.table)
df <- data.table(data.frame("indiv"=c(1,1,1,1,2,2,2,2,2,3,3,3,3),"value" =c(5,NA,NA,NA,NA,8,NA,NA,NA,7,NA,NA,NA)))
Desired output:
data.frame("indiv"=c(1,1,1,1,2,2,2,2,2,3,3,3,3),"value" =c(5,5,5,NA,NA,8,8,8,NA,7,7,7,NA))
Thank you very much for your help.