I need to fill in NA rows with the previous row value, but only until a criteria is not changed. As a simple example for days of week, meals and prices:
Day = c(
Another option using data.table
data.table
library(data.table) library(xts) dt <- data.table(df) dt[, Price := na.locf(Price, fromLast = TRUE), by = Meal]