I have one week of data with a reading every 5 seconds. An example of data is below.
9/1/2012 00:00:00 1
9/1/2012 00:00:05 2
9/1/2012 00:00:10 3
I want to calculate the hourly average for each day. Then make a multi-line plot of "average hourly reading vs. hour" with lines representing different dates.
The one I have here is for weekly average
data$date = as.POSIXct(strptime(data$date,
format = "%d/%m/%Y %H:%M","GMT"))
means <- aggregate(data["nox"], format(data["date"],"%Y-%U"),
mean, na.rm = TRUE)
For daily average, it is
data$date = as.POSIXct(strptime(data$date,
format = "%d/%m/%Y %H:%M","GMT"))
means <- aggregate(data["nox"], format(data["date"],"%Y-%j"),
mean, na.rm = TRUE)
Any one knows how to calculate the hourly average for each day.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…