Skip to content

setting zeros for missing interval in data

1 message · Jeff Newmiller

#
There are quite a variety of approaches implemented in various contributed packages, but here is a base R approach based on merge:

Sys.setenv(TZ = "UTC" ) # or other non-DST zone unless you need it
YY$TIMESTAMP <- as.POSIXct( YY$TIMESTAMP, format = "%Y/%m/%d %I:%M:%S %p" )
tlims <- as.POSIXct( c( "2021-05-02", "2021-05-10" ) )
tdiff <- as.difftime( 5, units="mins" )
aa <- seq( tlims[1], tlims[2], by = tdiff )
AA <- expand.grid( CHANNEL = 30, TIMESTAMP = aa )
yy <- merge( AA, YY[ , c( "CHANNEL", "TIMESTAMP", "RAINFALL" ) ], by = c( "CHANNEL", "TIMESTAMP" ), all.x = TRUE )
yy$RAINFALL[ is.na( yy$RAINFALL ) ] <- 0
yy
On February 28, 2022 7:52:47 PM PST, Eliza Botto <eliza_botto at outlook.com> wrote: