I am new in R, and I have a problem. I have a CSV data frame with more than 80000 entries. I have a column (maj) filled with 0 and 1, a column with each day of the year, and a column with the price per day (and other columns). When maj = 1 it means that an update on the price has been done that day. What I want to do is : If maj = 0 during the last 30 days, price has to be replaced by "N/A"
Here's a sample of my df :
day maj price
2019-01-02 1 1435
2019-01-03 0 1435
2019-01-04 0 1435
2019-01-05 0 1435
For example, if between the 2019-01-03 and the 2019-02-03 maj = 0, I want to replace the price by N/A for the 2019-02-04 and all the following, until maj=1 again.
I don't have any code to show because I erased it when I saw that nothing was working. I tried rollapplyr with the zoo package, it created a function and values to roll monthly sum, but I don't understand it.
Does anyone know how to do it ?
Thanks,