Skip to content
Prev 391160 / 398506 Next

Inserting missing seq number

Petr & Eric

Thank you for the two options.  Figured there was an easy straight forward
way.

Jeff

-----Original Message-----
From: PIKAL Petr <petr.pikal at precheza.cz> 
Sent: Wednesday, March 30, 2022 12:59 AM
To: reichmanj at sbcglobal.net
Cc: r-help at r-project.org
Subject: RE: [R] Inserting missing seq number

Hallo Jeff

Similar result you will get by na.locf function from zoo package

df <- data.frame(seq = c(1,2,4,5,7), count = c(4,7,3,5,2))
vec <-data.frame(seq =1:7)
df <- merge(vec, df, all=T)
library(zoo)
df$count <- na.locf(df$count)

Cheers
Petr