My data looks like this
> sample
  ID  Date
1  1    NA
2  1    NA
3  1 16436
4  1    NA
5  2    NA
6  2 16436
7  2    NA
8  2    NA
The data set I want is
> final
  ID       Date
1  1       <NA>
2  1       <NA>
3  1 2015-01-01
4  1       <NA>
5  2       <NA>
6  2 2015-01-01
7  2 2015-01-01
8  2 2015-01-01
The code I am using is
> final <- sample %>%
+ group_by(ID) %>%
+ mutate(Date = zoo:: na.locf(as.Date(Date,origin= "1970-01-01")))
Error: incompatible size (2), expecting 4 (the group size) or 1
Any help on the issue will be greatly appreciated
 
     
    