[R] Inserting missing seq number

Jeff Reichman re|chm@nj @end|ng |rom @bcg|ob@|@net
Wed Mar 30 04:47:02 CEST 2022


R-help

Is there a R function that will insert missing sequence number(s) and then
fill a missing observation with the preceding value.

For example df <- data.frame(seq = c(1,2,4,5,7), count = c(4,7,3,5,2))

  seq count
1    1        4
2    2        7
3    4        3
4    5        5
5    7        2

What I need is

  seq count
1    1        4
2    2        7
3    3        7
4    4        3
5    5        5
6    6        5
7    7        2

Jeff



More information about the R-help mailing list