I have a data frame of this type
YEAR MONTH DAY HOUR LON LAT
1860 10 3 13 -19.50 3.00
1860 10 3 17
I would try something along these lines. Since you mention that you only need to figure out the subsetting logic, I haven't bothered to add the correlation coeff calculation.
df$date <- as.Date(paste(df$YEAR,df$MONTH,df$DAY),'%Y %m %d')
uniquedates <- unique(df$date)
uniquedatesfourth <- uniquedates + 4
for ( i in seq(length(uniquedates)))
{
tempsubset <- subset(df, date >= uniquedates[i] & date >= uniquedatesfourth[i])
# operations on tempsubset
}