r - Further aggregation by specific groups -


i'm in process of taking data have , splitting smaller groups use in heat map. code have below, have read file, , make 8 different subsets. these subsets have aggregated them hour. data ranges beginning of may end, there 24(number of hourly intervals) * 31 = 744 rows. however, want further group these rows each subset. want final product 24(number of hourly intervals) * 7(number of days in week) = 168 rows. this, example, if there multiple groups interval 12pm - 1 on mondays, want average them together. then, want same rest. have idea how can this? appreciated.

#open file maydata <- read.csv("lengthbindata.csv", header=true) names(maydata) <- c("station", "lane", "bin", "count", "time")  #setting packages #install.packages("tseries") #install.packages("xts") #install.packages("quantmod") #install.packages("timedate") #install.packages("gridextra") #install.packages("ggthemes") #install.packages("lubridate")  library(tseries) library(xts) library(quantmod) library(timedate) library(reshape2) library(ggplot2) library(scales) library(gridextra)    library(ggthemes)  library(lubridate)  #splitting stations  glisannb <- subset(maydata, station == '228' & bin >= '2') glisansb <- subset(maydata, station == '248' & bin >= '2') carmannb <- subset(maydata, station == '82' & bin >= '2') carmansb <- subset(maydata, station == '87' & bin >= '2') marinenb <- subset(maydata, station == '171' & bin >= '2') marinesb <- subset(maydata, station == '187' & bin >= '2') staffordnb <- subset(maydata, station == '213' & bin >= '2') staffordsb <- subset(maydata, station == '231' & bin >= '2')  #setting components data frame  aggregation1 <- aggregate(glisannb['count'], list(hour=cut(as.posixct(glisannb$time), "hour")), sum) totals1 <- aggregation1[,2]  aggregation2 <- aggregate(glisansb['count'], list(hour=cut(as.posixct(glisansb$time), "hour")), sum) totals2 <- aggregation2[,2]  aggregation3 <- aggregate(carmannb['count'], list(hour=cut(as.posixct(carmannb$time), "hour")), sum) totals3 <- aggregation3[,2]  aggregation4 <- aggregate(carmansb['count'], list(hour=cut(as.posixct(carmansb$time), "hour")), sum) totals4 <- aggregation4[,2]  aggregation5 <- aggregate(marinenb['count'], list(hour=cut(as.posixct(marinenb$time), "hour")), sum) totals5 <- aggregation5[,2]  aggregation6 <- aggregate(marinesb['count'], list(hour=cut(as.posixct(marinesb$time), "hour")), sum) totals6 <- aggregation6[,2]  aggregation7 <- aggregate(staffordnb['count'], list(hour=cut(as.posixct(staffordnb$time), "hour")), sum) totals7 <- aggregation7[,2]  aggregation8 <- aggregate(staffordsb['count'], list(hour=cut(as.posixct(staffordsb$time), "hour")), sum) totals8 <- aggregation8[,2] 


Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -