Suppose I have dataset which looks like
ID Name
1 JAY
1
1 JAY
2 LAY
2 LAY
2
3 NA
3 KAY
3
I want to fill the rows with missing values(empty or with NA) based on the observation already available in the group. So the resultant data frame will look like
ID Name
1 JAY
1 JAY
1 JAY
2 LAY
2 LAY
2 LAY
3 KAY
3 KAY
3 KAY
I tried using na.locf
but it didnt work for non numeric value.
DF1 = setDT(DF)[, N := na.locf(na.locf(Name(NA_real_^!Name),na.rm=FALSE), fromLast=TRUE, na.rm=FALSE), ID][is.na(N), N := 0]