My data have the following form:
I want to create a loop that every time will take the observations from the beginning till the next 15 minutes, then after the first 15 minutes to additional 15 minutes, etc and will calculate the mean of the values for each sensor. I want to find the difference in the change in mean values per 15 minutes per sensor. I have set the date as
dtm <- strptime("21/09/2015 10:41:00", format = "%d/%m/%Y %H:%M:%S",
tz = "CET")
and the function for the minutes.
mns <- function(m) {x <- m * 60 return(x)}
quart=rep(NA,nrow(data))
mean.min=rep(NA,nrow(data))
diff.min=rep(NA,nrow(data))
for (i in 0:4){
quart[i] <- data[data$Date >= dtm+mns(15)*i & data$Date <= dtm+mns(15)*(i+1),]
data$mean.min[i]<-aggregate(quart[i]$Value~quart[i]$SensorId, FUN=mean)
data$diff.min[i+1]<-rowMeans(abs(data$mean.min[i+1]-data$mean.min[i]),na.rm=T)}