Hi All,
I am trying to add Temp in such a way that for a given event it will sum till Duration=1.
If Duration>1 for a given Event, it will start from the next row to add up.
I want to get as provided in the expected outcome.
rm(list = ls())
time=c("9/3/1976 23:00","9/3/1976 23:15", "9/4/1976 2:15","9/4/1976 15:30", "9/4/1976 15:45", "9/4/1976 16:15",
"9/6/1976 13:45" ,"9/6/1976 14:00", "9/6/1976 14:15", "9/6/1976 14:30", "9/6/1976 15:00", "9/6/1976 19:30",
"9/6/1976 19:45")
Temp=as.numeric(c(2.54,5.08,2.54,5.18,2.54,2.54,2.54,12.7,
2.54,2.54,2.54,2.54,2.54))
Duration=as.numeric(rep(0.25,13))
Event=as.numeric(c(1,1,1,2,2,2,3,3,3,3,3,3,3))
df=cbind(time,Temp,Duration,Event)
df=as.data.frame(df)
df$time=as.POSIXct(df$time,format="%m/%d/%Y %H:%M")
df$month=format(as.Date(df$time, format="%m/%d/%Y %H:%M"),"%m")
head(df)
df$timescale=as.numeric(df$timescale)
head(df)
#Expected Outcome
Temp Duration Event month
10.16 0.75 1 9
10.26 0.75 2 9
20.32 1 3 9
7.62 0.75 3 9
Thanks for your time.