Hello R community, I need to do some aggregation based on the test data below. The below code works ok, but when its applied to my real data which includes over 9,000 records the process runs for over an hour. I know there is a more efficient way of doing this. I want to Sum the below data's volumes where FNODE and TNODE match,
i.e. FNODE=1 and TNODE =20 -> Volume=100 , FNODE=20 and TNODE =1 -> Volume=100 These should be aggregated toTotalVolume= 200. Also, there are some link without partner links(see record 21 in test data). This record should not be summed with another link since there isnt a compliment to sum with. Thanks in advance. -JR #Create test data TNode<-c(1:20,21) FNode<-c(rev(1:20),22) Volume<-c(rep(100,20),200) ClassCode=c(rep("Local",20),rep("Freeway",1)) #Create data frame with test data EmmeData..<-data.frame(TNode=TNode,FNode=FNode,Volume=Volume,ClassCode=ClassCode) #Create list to store results LinkSum_<-list() #Create vecotrs to establish loops TNodes<-unique(EmmeData..$TNode) FNodes<-unique(EmmeData..$FNode) for(tn in TNodes){ for(fn in FNodes){ TF<-EmmeData..[EmmeData..$TNode==tn & EmmeData..$FNode==fn,] FT<-EmmeData..[EmmeData..$TNode==fn & EmmeData..$FNode==tn,] if(length(TF$TNode)>0){ LinkSum_[[tn]]<-list(ID=list(c(TF$TNode,TF$FNode)),ClassCode=TF$ClassCode,TotalVolume=TF$Volume+FT$Volume) } } } -- View this message in context: http://r.789695.n4.nabble.com/Aggregate-on-identical-link-attributes-tp3044009p3044009.html Sent from the R help mailing list archive at Nabble.com. ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.