####################FUNCTIONS TO CLEAN A LIST OF TRIANGLES ########################### load(file="trianglesList.RData") createDbFromTriangle<-function(trianglesList) { for(i in 1:length(trianglesList$triangles)) { myTriangle<-trianglesList$triangles[[i]] nameOfGroup<-trianglesList$groups[i] triangleDf<-as.data.frame(cum2incr(myTriangle)) triangleDf$group=nameOfGroup if(exists("out")) out<-rbind(out, triangleDf) else out<-triangleDf } #identify AYs without payments rows2remove<-subset(aggregate(value~ay+group,data=out,FUN="sum"), value==0) names(rows2remove)[3]<-"check" temp<-merge(out, rows2remove,all.x=TRUE) out<-subset(temp, is.na(check)) out$check<-NULL #elimitate developments in the low part of the triangle out<-subset(out, is.finite(value)) #CHECK! put 1 when payments = negative out$value[out$value<0]=1 rownames(out)<-NULL invisible(out) } #createsa data base containing all the triangles for all the group in list commercialAutoDb<-createDbFromTriangle(commercialAutoList) privatePassengerAutoDb<-createDbFromTriangle(privatePassengerAutoList) workersCompensationDb<-createDbFromTriangle(workersCompensationList) medicalMalpracticeDb<-createDbFromTriangle(medicalMalpracticeList) otherLiabilityDb<-createDbFromTriangle(otherLiabilityList) productLiabilityDb<-createDbFromTriangle(productLiabilityList)