With only one observation per day, it is not possible to compute a correlation.
But you can compute the correlations on a moving window, e.g., with rollapply
.
# Convert the data to time series
library(zoo)
d <- zoo(
airquality,
sprintf( "%02i-%02i", airquality$Month, airquality$Day )
)
# Compute the correlations
r <- rollapply(
d,
width = 7,
FUN = function(u) c(
cor(u[,"Ozone"], u[,"Temp"], use="pairwise"),
cor(u[,"Ozone"], u[,"Wind"], use="pairwise")
),
by.column = FALSE,
align = "right"
)
# Plot
matplot( 1:nrow(r), r, type="l", lwd=3, lty=1, axes=FALSE )
axis(2, las=1)
axis(1, at=1:nrow(r), labels=index(r), las=2)
box()