So my problem is that I'm trying to do a moving average that with the function slide_index_dbl.
The data I have that I'll use do get a index is:
The .i is variable created : {Date[1:35585], format: "2018-07-10" .}
The .x is the variable of {price: num[1:35585], format: 64900...}
The arrange and group_by variable used is {segment: chr[1:35585], format:"A" "B" "C"..."SUV"}
The code I'm running is:
install.packages("slider")
library(slider)
dv_r <- dvdate %>% select(c(created, distance, price, segment) %>%
arrange(segment, created) %>%
group_by(segment) %>%
mutate(avg90=slide_index_dbl( .x = price, .i = created, .f = ~mean(.x, na.rm = FALSE), .before = days(90)))
I have my variables(segment and created) in ascending order but the error message is still:
Error in `stop_slider()`:
! `.i` must be in ascending order.
i It is not ascending at locations: 33401, 27747, 27751, 33403,....
Any reason for this? Is my date variable wrong or what could it be?
Any help or guidens to a solution is of much help