I am attempting to make a new column that is based on the values in the following 3 rows but cant seem to get the condition/format to work ?
I have a dataframe (hh01) with the following columns ([#] = the column number): ... [16]temp_avg, [17]temp_avg_next, [18] temp_change_30 ... 10.405, 10.375, -0.03 ... 10.375, 10.17333, -0.2016667 ... 10.17333, 9.9400, -0.2333333
[16] and [17] are temperature measurements and [18] is the change over the subsequent 30 minutes (found by subtracting [17] - [16])
I want to create a new column "heat_on" that indicates if the heat is turned on based on a subsequent 3 periods of temperature change (captured by temp_change_30)
if the temperature increases for the following 3 periods then heat_on==1, if the temperature decreases for the following 3 periods then the heat_on==0, and if the temperature changes variably/not consistently increasing or decreasing i want to mark this with a 2 so heat_on==2 in all other cases
I wrote the following code
hh01$heat_on <- hh01%>%mutate(heat_on = case_when( temp_change_30<0 & c(temp_change_30[-1, ])<0 & c(temp_change_30[-2, ])<0 ~ 0, temp_change_30>0 & c(temp_change_30[-1, ])>0 & c(temp_change_30[-2, ])>0 ~ 1, FALSE ~ 2 ))
the code will not all the way through and im not sure if its because I am not capturing how to reference the next observation in the row correctly or something else entirely im missing
ThankS!