I have a multi-day XTS object, and I am trying to create an indicator that once true, remains true for the rest of the day. The approach I am trying (but its not working) is com
One option is
y1 <- ave(y, as.Date(index(y)), FUN= function(x) na.locf(x, na.rm=FALSE))
y1
# [,1]
#2010-01-05 00:00:00 NA
#2010-01-05 00:04:00 NA
#2010-01-05 00:08:00 1
#2010-01-05 00:12:00 1
#2010-01-05 00:16:00 1
#2010-01-05 00:20:00 1
#2010-01-06 00:00:00 NA
#2010-01-06 00:04:00 NA
#2010-01-06 00:08:00 NA
str(y1)
# An ‘xts’ object on 2010-01-05/2010-01-06 00:08:00 containing:
# Data: num [1:9, 1] NA NA 1 1 1 1 NA NA NA
# Indexed by objects of class: [POSIXct,POSIXt] TZ:
# Original class: 'double'
# xts Attributes:
# NULL
str(y)
#An ‘xts’ object on 2010-01-05/2010-01-06 00:08:00 containing:
# Data: num [1:9, 1] NA NA 1 NA NA NA NA NA NA
# Indexed by objects of class: [POSIXct,POSIXt] TZ:
# Original class: 'double'
# xts Attributes:
# NULL