Fill missing values based on group
In R this is usually solved using the na.locf (Last Observation Carried Forward) function from the zoo package.

See also here:


Fill in NA based on the last non-NA value for each group in R
Using dplyr window-functions to make trailing values




# test data
x &lt;- read.table(text="id;date
1;23-04
1;23-04
1;NA
1;NA
2;24-04
2;NA
2;NA
2;NA
3;23-04
3;NA
3;NA
3;NA
4;NA
4;NA
4;NA
4;NA", header=TRUE, sep=";")

library("dplyr")
library("zoo")

x %&gt;% group_by(id) %&gt;% transmute(date=na.locf(date, na.rm=FALSE))
Source: local data frame [16 x 2]
Groups: id

   id  date
1   1 23-04
2   1 23-04
3   1 23-04
4   1 23-04
5   2 24-04
6   2 24-04
7   2 24-04
8   2 24-04
9   3 23-04
10  3 23-04
11  3 23-04
12  3 23-04
13  4    NA
14  4    NA
15  4    NA
16  4    NA


Another option are rolling self-joins supported by the data.table package (see here).