I have a dataframe called prices_df to which I add an extra column and conditionally fill, based on the contents of another column in the same df, with a 1
prices_df$itd_1 <- c(NA)
prices_df$itd_1 <- with( prices_df , ifelse(V2.1==1 , 1, NA) )
which gives a 1 in the last column thus
2005-11-16,NA,NA,NA,NA,1,NA,NA,NA,NA,NA,NA,NA,1
2005-11-17,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA
2005-11-18,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA
However, what I would also like to do to is offset this conditional fill such that the output will be, for example, 1 in the column two rows later than the reference column, or perhaps x rows earlier or later, e.g.
2005-11-16,NA,NA,NA,NA,1,NA,NA,NA,NA,NA,NA,NA,NA
2005-11-17,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA
2005-11-18,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,1
How can I adjust the given code to achieve this offset conditional filling?
Best way is to:
Merge everything together