sum_temp<-c()
for (i in 1:length(Station$Day)){
if (Station$Day[i] == Station$Day[i+1]){
sum_temp <- sum_temp + Station$h_temp[i]
} else
mean_temp <- mean(sum_temp)
# put the value in a new table but not of importance here
sum_temp <- 0
}
Hi, I have a data frame containing 9 columns with "Day" as POSIXlt and several meteorological parameters as numeric. What I am trying to do in the loop is to calculate the daily mean since temperature is recorded hourly, hence each day has 24 lines. For this I ask if Day in line i is the same as in line i+1. If yes, sum up the values as long as this statement is true. If the statement is false, calculate the mean and set the sum back to 0. However, I receive the error message "missing value where TRUE/FALSE needed". Btw there is no NA in it.
Can anybody see the mistake? Thanks a lot!