Okay, I think I understand what you're recommending here. I think I may have oversimplified my reprex relative to my dataset. Here's a better example, I think. If I make the reprex something like this, using that same DAX column and adding a column to represent the (fake) day of the week when the observation was taken:
library(tidyverse)
#> Warning: package 'tidyverse' was built under R version 4.0.3
df <- data.frame(DAX = c(1628.75, 1613.63, 1606.51, 1621.04, 1618.16, 1636.78, 1632.17),
Day.Of.Week = c("1", "2", "4", "5", "1", "2", "3"))
Created on 2021-02-14 by the reprex package (v1.0.0)
My goal would be to maintain the structure of that dataframe I created while inserting the row. So in this case, if I want to find that change_in_dax for observations taken on consecutive days (i.e. if lead(Day.Of.Week) - Day.Of.Week = 1), I would use a for loop to do this. My pseudocode for this would look something like:
for ("every row in the dataframe"){
if ("the observations are separated by 1 day") {
"insert row in between the two rows with some descriptor about how the observations changed"
}
}
And then after running that code, I would ideally end up with a df that looks something like
df <- data.frame(DAX = c(1628.75, -15.12, 1613.63, 1606.51, 14.53, 1621.04, 1618.16, 1636.78, 1632.17),
Day.Of.Week = c(1, 0, 2, 4, 0, 5, 1, 3, 5))
though the Day.Of.Week could definitely be something besides 0, that's just to preserve the class of the vector as numeric, the row insertion is what I'm more concerned about. Does that still make sense? Sorry, and thank you very much for your help.