Ok, in lieu of a reprex from you, lets do detective work.
Here is a simple scenario I made that at least reproduces the error message, even though it may not be relevant to your data.
library(tidyverse)
library(slider)
library(lubridate)
(slidable <- structure(list(seg = c("a", "a", "a", "b", "b", "b"),
d = structure(c(19108, 19109, 19110, 19108, 19109, 19110), class = "Date"),
v = 1:6), row.names = c(NA, -6L), class = "data.frame"))
slidable %>% group_by(seg) %>% mutate(
avg_v =slide_index_dbl( .x = v,
.i = d,
.f = ~mean(.x, na.rm = FALSE),
.before = days(2)))
# ijust reversed the dates for seg b
(unslidable <- structure(list(seg = c("a", "a", "a", "b", "b", "b"),
d = structure(c(19108, 19109, 19110, 19110, 19109, 19108), class = "Date"),
v = 1:6), row.names = c(NA, -6L), class = "data.frame"))
unslidable %>% group_by(seg) %>% mutate(
avg_v =slide_index_dbl( .x = v,
.i = d,
.f = ~mean(.x, na.rm = FALSE),
.before = days(2)))
I learn from this that
error in `stop_slider()`:
! `.i` must be in ascending order.
i It is not ascending at locations: 3, 2.
at least in my example is only the last part of a longer and more helpful error message, which in full is
Error in `mutate()`:
! Problem while computing `avg_v = slide_index_dbl(...)`.
i The error occurred in group 2: seg = "b".
Caused by error in `stop_slider()`:
! `.i` must be in ascending order.
i It is not ascending at locations: 3, 2.
Run `rlang::last_error()` to see where the error occurred
This is helpful as it identifies the segment 'b' as the problematic one, it therefore gives context to locations 3,2 as these relate to the in segment locations.
Do you have a larger error message in your real issue that we can draw information from ?