0

Here is an example of my problem:

df<-data.frame(x=c("A", NA, NA, NA, "B", NA, NA, "D", NA, NA))
df
      x
1     A
2  <NA>
3  <NA>
4  <NA>
5     B
6  <NA>
7  <NA>
8     D
9  <NA>
10 <NA>

My question is what it is the best way to reach this:

df
      x
1     A
2     A
3     A
4     A
5     B
6     B
7     B
8     D
9     D
10    D

Namely repeat the column items to replace the NAs following until the next not a NA. Is there a easy to realize it?

David Z
  • 6,641
  • 11
  • 50
  • 101

0 Answers0