I am struggeling to get maximum value of variable from last year of observations (Not each year!) and implement it to each row (observation).
I think the best way to do so is using the rollapply function but I cannot figure out how the width should look like since it may vary for each observation (each observation represents a day but not all days have observations). I know that using list will make offset values so how sould these values look like ?
The code I got:
mutate(data,"Feature"=rollapplyr(variable,list(0,"Go back one year"),max,fill=NA))
Example in order to clarify: a row has date of 31/8/2016. I want the new column (using mutate of dplyr package) to display in this row the maximum value of variable
from 31/8/2015 to 31/8/2016 (this row).
For those who want to go further:
Instead of displaying the variable
value - display TRUE
or FALSE
(or 1
/ 0
) when calculated maximum variable
is above threshold value.