r - Storing print output -
i simulating football results using r, have set loop each team plays against each other.
mod3=glm(formula = score ~ attack +home+division , family = poisson, data = football) (i in 1:20){ (j in 1:20){ if (i!=j){ teamhome=levels(football$attack)[i] teamaway=levels(football$attack)[j] teamhome teamaway if(i<21){ iteam="p" } else if(i<45){ iteam="c" } else if(i<69){ iteam="1" } else{ iteam="2" } if(j<21){ jteam="p" } else if(j<45){ jteam="c" } else if(j<69){ jteam="1" } else{ jteam="2" } if(iteam==jteam) {iteam <- "s"; jteam <-"s"} divisions=paste(iteam,jteam," ",sep="") divisionj=paste(jteam,iteam," ",sep="") homescore=rpois(1,predict.glm(mod3, data.frame(attack=teamhome,home="y ",division=divisions),type="response")) awayscore=rpois(1,predict.glm(mod3, data.frame(attack=teamaway, home="n ",division=divisionj),type="response")) result= if(homescore>awayscore){ result="h" } else if(homescore<awayscore){ result="a" }else if(homescore==awayscore){ result="d" } results<-print(paste(teamhome,homescore," ",teamaway,awayscore,divisions,divisionj,result),quote=f)
when run loop results like:
[1] qpr 0 arsenal 1 ss ss [1] qpr 1 tottenham 1 ss ss d [1] qpr 2 everton 1 ss ss h [1] qpr 1 liverpool 2 ss ss [1] qpr 2 wba 1 ss ss h [1] qpr 0 swansea 2 ss ss
where need results stored @ different levels can tally amount of h
, a
, d
right team, , number of goals team scored or conceded.
how can store print output ?
Comments
Post a Comment