I'm working with some meteorology data in R, and conceptually, I'm trying to find out how much a certain day is above/below average. To do this, I want to separate by day of year, find the average for all DOY (e.g. what is the average January 1 Temperature?), and then compare every date (e.g was January 1, 2014 anomalously warm, by how much?)
I can find a 'mean' table for every day of the year using aggregate:
head(data)
x date
1 5.072241 1970-01-01
2 6.517069 1970-01-02
3 4.413654 1970-01-03
4 11.129351 1970-01-04
5 9.331630 1970-01-05
library(lubridate)
temp = aggregate(data$x, list(yday(data$date)), mean)
but I'm stuck then how to use the aggregated table to compare with my original data.frame, to see how x at 1970 Jan 1 relates to average Jan 1 x.