there is a dataframe as blow(with NA values)
md <- data.frame(cat=c('a','b','d',NA,'E',NA),
subcat=c('A','C',NA,NA,NA,'D'))
cat subcat
1 a A
2 b C
3 d <NA>
4 <NA> <NA>
5 E <NA>
6 <NA> D
i want to replace the NA by the previous character ,the result as below.
Using loop statement like 'for ...' can do it, but it's not that efficient . is there any formula or package can do it ? thanks!
cat subcat
1 a A
2 b C
3 d C
4 d C
5 E C
6 E D
NA
? – Heterotypic