# Dummy data
x <- data.frame(
date=as.POSIXct(1:10000,origin="2005-01-01 12:00:00"),
receiver=rep(letters[1:10],1000),
Latitude=rep(letters[1:10],1000),
Longitude=rep(letters[1:10],1000),
ndiffs29912=rnorm(10000)+10)
# Break dates into hours using cut append to data frame
x$hour <- cut(x$date, breaks="hour")
library(plyr)
# By hour and latitude, get weighted
# mean of ndiffs based on number of receivers
ddply(x, .(hour, latitude), function(x) data.frame(
weighted.mean(x$ndiffs29912, length(x$receiver), na.rm=T))
# By hour and longitude, get weighted
# mean of ndiffs based on number of receivers
ddply(x, .(hour, longitude), function(x) data.frame(
weighted.mean(x$ndiffs29912, length(x$receiver), na.rm=T))