I think I am mostly there, but I can't figure out the remaining piece of how to code this properly.
I begin with a single column of 15 values. I want to create two new columns with the 'previous' containing the average of the previous two values, and the 'future' creating the average of the next two values.
My code is failing because it is INCLUSIVE of the current row's values.
For example, row3 or '30' should have a 'previous' value of 15 ((10+20/2)) and a future value of 45 ((40+50)/2). instead it is returning 25 and 35 because it is including the 30 with the 20 or 40 when making the averages.
I also am stuck on how to just display the previous value.
Anyone mind telling me how to avoid this problem that I am experiencing?
I am using filter but I don't know if there is a better way to do this..
values=data.frame(col=c(10,20,30,40,50,60,70,80,90,100,110,120,130,140,150))
values$previous2 = filter(values$col, rep(1/2,2),sides=1)
values$future2 = filter(values$col, rep(1/2,2),sides=2)
values$last = #should be the previous value - ex 2nd row should be 10
values