我已经处理了LaTeX中的参数化代码,所以我确信R还有一个等价物。下面的代码块是我需要压缩的代码,以便将来我可以进一步优化代码。
Model$AttackHome[Model$Home == "Arsenal"] <- AP$AttackHome[1]
Model$AttackHome[Model$Home == "Bournemouth"] <- AP$AttackHome[2]
Model$AttackHome[Model$Home == "Burnley"] <- AP$AttackHome[3]
Model$AttackHome[Model$Home == "Chelsea"] <- AP$AttackHome[4]
Model$AttackHome[Model$Home == "Crystal Palace"] <- AP$AttackHome[5]
Model$AttackHome[Model$Home == "Everton"] <- AP$AttackHome[6]
Model$AttackHome[Model$Home == "Hull"] <- AP$AttackHome[7]
Model$AttackHome[Model$Home == "Leicester"] <- AP$AttackHome[8]
Model$AttackHome[Model$Home == "Liverpool"] <- AP$AttackHome[9]
Model$AttackHome[Model$Home == "Man City"] <- AP$AttackHome[10]
Model$AttackHome[Model$Home == "Man United"] <- AP$AttackHome[11]
Model$AttackHome[Model$Home == "Middlesbrough"] <- AP$AttackHome[12]
Model$AttackHome[Model$Home == "Southampton"] <- AP$AttackHome[13]
Model$AttackHome[Model$Home == "Stoke"] <- AP$AttackHome[14]
Model$AttackHome[Model$Home == "Sunderland"] <- AP$AttackHome[15]
Model$AttackHome[Model$Home == "Swansea"] <- AP$AttackHome[16]
Model$AttackHome[Model$Home == "Tottenham"] <- AP$AttackHome[17]
Model$AttackHome[Model$Home == "Watford"] <- AP$AttackHome[18]
Model$AttackHome[Model$Home == "West Brom"] <- AP$AttackHome[19]
Model$AttackHome[Model$Home == "West Ham"] <- AP$AttackHome[20]
Model$AttackAway[Model$Away == "Arsenal"] <- AP$AttackAway[1]
Model$AttackAway[Model$Away == "Bournemouth"] <- AP$AttackAway[2]
Model$AttackAway[Model$Away == "Burnley"] <- AP$AttackAway[3]
Model$AttackAway[Model$Away == "Chelsea"] <- AP$AttackAway[4]
Model$AttackAway[Model$Away == "Crystal Palace"] <- AP$AttackAway[5]
Model$AttackAway[Model$Away == "Everton"] <- AP$AttackAway[6]
Model$AttackAway[Model$Away == "Hull"] <- AP$AttackAway[7]
Model$AttackAway[Model$Away == "Leicester"] <- AP$AttackAway[8]
Model$AttackAway[Model$Away == "Liverpool"] <- AP$AttackAway[9]
Model$AttackAway[Model$Away == "Man City"] <- AP$AttackAway[10]
Model$AttackAway[Model$Away == "Man United"] <- AP$AttackAway[11]
Model$AttackAway[Model$Away == "Middlesbrough"] <- AP$AttackAway[12]
Model$AttackAway[Model$Away == "Southampton"] <- AP$AttackAway[13]
Model$AttackAway[Model$Away == "Stoke"] <- AP$AttackAway[14]
Model$AttackAway[Model$Away == "Sunderland"] <- AP$AttackAway[15]
Model$AttackAway[Model$Away == "Swansea"] <- AP$AttackAway[16]
Model$AttackAway[Model$Away == "Tottenham"] <- AP$AttackAway[17]
Model$AttackAway[Model$Away == "Watford"] <- AP$AttackAway[18]
Model$AttackAway[Model$Away == "West Brom"] <- AP$AttackAway[19]
Model$AttackAway[Model$Away == "West Ham" ] <- AP$AttackAway[20]
Model$DefenceHome[Model$Home == "Arsenal"] <- DP$DefenceHome[1]
Model$DefenceHome[Model$Home == "Bournemouth"] <- DP$DefenceHome[2]
Model$DefenceHome[Model$Home == "Burnley"] <- DP$DefenceHome[3]
Model$DefenceHome[Model$Home == "Chelsea"] <- DP$DefenceHome[4]
Model$DefenceHome[Model$Home == "Crystal Palace"] <- DP$DefenceHome[5]
Model$DefenceHome[Model$Home == "Everton"] <- DP$DefenceHome[6]
Model$DefenceHome[Model$Home == "Hull"] <- DP$DefenceHome[7]
Model$DefenceHome[Model$Home == "Leicester"] <- DP$DefenceHome[8]
Model$DefenceHome[Model$Home == "Liverpool"] <- DP$DefenceHome[9]
Model$DefenceHome[Model$Home == "Man City"] <- DP$DefenceHome[10]
Model$DefenceHome[Model$Home == "Man United"] <- DP$DefenceHome[11]
Model$DefenceHome[Model$Home == "Middlesbrough"] <- DP$DefenceHome[12]
Model$DefenceHome[Model$Home == "Southampton"] <- DP$DefenceHome[13]
Model$DefenceHome[Model$Home == "Stoke"] <- DP$DefenceHome[14]
Model$DefenceHome[Model$Home == "Sunderland"] <- DP$DefenceHome[15]
Model$DefenceHome[Model$Home == "Swansea"] <- DP$DefenceHome[16]
Model$DefenceHome[Model$Home == "Tottenham"] <- DP$DefenceHome[17]
Model$DefenceHome[Model$Home == "Watford"] <- DP$DefenceHome[18]
Model$DefenceHome[Model$Home == "West Brom"] <- DP$DefenceHome[19]
Model$DefenceHome[Model$Home == "West Ham"] <- DP$DefenceHome[20]
Model$DefenceAway[Model$Away == "Arsenal"] <- DP$DefenceAway[1]
Model$DefenceAway[Model$Away == "Bournemouth"] <- DP$DefenceAway[2]
Model$DefenceAway[Model$Away == "Burnley"] <- DP$DefenceAway[3]
Model$DefenceAway[Model$Away == "Chelsea"] <- DP$DefenceAway[4]
Model$DefenceAway[Model$Away == "Crystal Palace"] <- DP$DefenceAway[5]
Model$DefenceAway[Model$Away == "Everton"] <- DP$DefenceAway[6]
Model$DefenceAway[Model$Away == "Hull"] <- DP$DefenceAway[7]
Model$DefenceAway[Model$Away == "Leicester"] <- DP$DefenceAway[8]
Model$DefenceAway[Model$Away == "Liverpool"] <- DP$DefenceAway[9]
Model$DefenceAway[Model$Away == "Man City"] <- DP$DefenceAway[10]
Model$DefenceAway[Model$Away == "Man United"] <- DP$DefenceAway[11]
Model$DefenceAway[Model$Away == "Middlesbrough"] <- DP$DefenceAway[12]
Model$DefenceAway[Model$Away == "Southampton"] <- DP$DefenceAway[13]
Model$DefenceAway[Model$Away == "Stoke"] <- DP$DefenceAway[14]
Model$DefenceAway[Model$Away == "Sunderland"] <- DP$DefenceAway[15]
Model$DefenceAway[Model$Away == "Swansea"] <- DP$DefenceAway[16]
Model$DefenceAway[Model$Away == "Tottenham"] <- DP$DefenceAway[17]
Model$DefenceAway[Model$Away == "Watford"] <- DP$DefenceAway[18]
Model$DefenceAway[Model$Away == "West Brom"] <- DP$DefenceAway[19]
Model$DefenceAway[Model$Away == "West Ham" ] <- DP$DefenceAway[20]
Model$AverageHFShots[Model$Home == "Arsenal"] <- SoModel$AverageHFShots[1]
Model$AverageHFShots[Model$Home == "Bournemouth"] <- SoModel$AverageHFShots[2]
Model$AverageHFShots[Model$Home == "Burnley"] <- SoModel$AverageHFShots[3]
Model$AverageHFShots[Model$Home == "Chelsea"] <- SoModel$AverageHFShots[4]
Model$AverageHFShots[Model$Home == "Crystal Palace"] <- SoModel$AverageHFShots[5]
Model$AverageHFShots[Model$Home == "Everton"] <- SoModel$AverageHFShots[6]
Model$AverageHFShots[Model$Home == "Hull"] <- SoModel$AverageHFShots[7]
Model$AverageHFShots[Model$Home == "Leicester"] <- SoModel$AverageHFShots[8]
Model$AverageHFShots[Model$Home == "Liverpool"] <- SoModel$AverageHFShots[9]
Model$AverageHFShots[Model$Home == "Man City"] <- SoModel$AverageHFShots[10]
Model$AverageHFShots[Model$Home == "Man United"] <- SoModel$AverageHFShots[11]
Model$AverageHFShots[Model$Home == "Middlesbrough"] <- SoModel$AverageHFShots[12]
Model$AverageHFShots[Model$Home == "Southampton"] <- SoModel$AverageHFShots[13]
Model$AverageHFShots[Model$Home == "Stoke"] <- SoModel$AverageHFShots[14]
Model$AverageHFShots[Model$Home == "Sunderland"] <- SoModel$AverageHFShots[15]
Model$AverageHFShots[Model$Home == "Swansea"] <- SoModel$AverageHFShots[16]
Model$AverageHFShots[Model$Home == "Tottenham"] <- SoModel$AverageHFShots[17]
Model$AverageHFShots[Model$Home == "Watford"] <- SoModel$AverageHFShots[18]
Model$AverageHFShots[Model$Home == "West Brom"] <- SoModel$AverageHFShots[19]
Model$AverageHFShots[Model$Home == "West Ham"] <- SoModel$AverageHFShots[20]
Model$AverageAFShots[Model$Away == "Arsenal"] <- SoModel$AverageAFShots[1]
Model$AverageAFShots[Model$Away == "Bournemouth"] <- SoModel$AverageAFShots[2]
Model$AverageAFShots[Model$Away == "Burnley"] <- SoModel$AverageAFShots[3]
Model$AverageAFShots[Model$Away == "Chelsea"] <- SoModel$AverageAFShots[4]
Model$AverageAFShots[Model$Away == "Crystal Palace"] <- SoModel$AverageAFShots[5]
Model$AverageAFShots[Model$Away == "Everton"] <- SoModel$AverageAFShots[6]
Model$AverageAFShots[Model$Away == "Hull"] <- SoModel$AverageAFShots[7]
Model$AverageAFShots[Model$Away == "Leicester"] <- SoModel$AverageAFShots[8]
Model$AverageAFShots[Model$Away == "Liverpool"] <- SoModel$AverageAFShots[9]
Model$AverageAFShots[Model$Away == "Man City"] <- SoModel$AverageAFShots[10]
Model$AverageAFShots[Model$Away == "Man United"] <- SoModel$AverageAFShots[11]
Model$AverageAFShots[Model$Away == "Middlesbrough"] <- SoModel$AverageAFShots[12]
Model$AverageAFShots[Model$Away == "Southampton"] <- SoModel$AverageAFShots[13]
Model$AverageAFShots[Model$Away == "Stoke"] <- SoModel$AverageAFShots[14]
Model$AverageAFShots[Model$Away == "Sunderland"] <- SoModel$AverageAFShots[15]
Model$AverageAFShots[Model$Away == "Swansea"] <- SoModel$AverageAFShots[16]
Model$AverageAFShots[Model$Away == "Tottenham"] <- SoModel$AverageAFShots[17]
Model$AverageAFShots[Model$Away == "Watford"] <- SoModel$AverageAFShots[18]
Model$AverageAFShots[Model$Away == "West Brom"] <- SoModel$AverageAFShots[19]
Model$AverageAFShots[Model$Away == "West Ham" ] <- SoModel$AverageAFShots[20]
Model$HGoalPerShots[Model$Home == "Arsenal"] <- GRT$HGoalPerShots[1]
Model$HGoalPerShots[Model$Home == "Bournemouth"] <- GRT$HGoalPerShots[2]
Model$HGoalPerShots[Model$Home == "Burnley"] <- GRT$HGoalPerShots[3]
Model$HGoalPerShots[Model$Home == "Chelsea"] <- GRT$HGoalPerShots[4]
Model$HGoalPerShots[Model$Home == "Crystal Palace"] <- GRT$HGoalPerShots[5]
Model$HGoalPerShots[Model$Home == "Everton"] <- GRT$HGoalPerShots[6]
Model$HGoalPerShots[Model$Home == "Hull"] <- GRT$HGoalPerShots[7]
Model$HGoalPerShots[Model$Home == "Leicester"] <- GRT$HGoalPerShots[8]
Model$HGoalPerShots[Model$Home == "Liverpool"] <- GRT$HGoalPerShots[9]
Model$HGoalPerShots[Model$Home == "Man City"] <- GRT$HGoalPerShots[10]
Model$HGoalPerShots[Model$Home == "Man United"] <- GRT$HGoalPerShots[11]
Model$HGoalPerShots[Model$Home == "Middlesbrough"] <- GRT$HGoalPerShots[12]
Model$HGoalPerShots[Model$Home == "Southampton"] <- GRT$HGoalPerShots[13]
Model$HGoalPerShots[Model$Home == "Stoke"] <- GRT$HGoalPerShots[14]
Model$HGoalPerShots[Model$Home == "Sunderland"] <- GRT$HGoalPerShots[15]
Model$HGoalPerShots[Model$Home == "Swansea"] <- GRT$HGoalPerShots[16]
Model$HGoalPerShots[Model$Home == "Tottenham"] <- GRT$HGoalPerShots[17]
Model$HGoalPerShots[Model$Home == "Watford"] <- GRT$HGoalPerShots[18]
Model$HGoalPerShots[Model$Home == "West Brom"] <- GRT$HGoalPerShots[19]
Model$HGoalPerShots[Model$Home == "West Ham"] <- GRT$HGoalPerShots[20]
Model$AGoalPerShots[Model$Away == "Arsenal"] <- GRT$AGoalPerShots[1]
Model$AGoalPerShots[Model$Away == "Bournemouth"] <- GRT$AGoalPerShots[2]
Model$AGoalPerShots[Model$Away == "Burnley"] <- GRT$AGoalPerShots[3]
Model$AGoalPerShots[Model$Away == "Chelsea"] <- GRT$AGoalPerShots[4]
Model$AGoalPerShots[Model$Away == "Crystal Palace"] <- GRT$AGoalPerShots[5]
Model$AGoalPerShots[Model$Away == "Everton"] <- GRT$AGoalPerShots[6]
Model$AGoalPerShots[Model$Away == "Hull"] <- GRT$AGoalPerShots[7]
Model$AGoalPerShots[Model$Away == "Leicester"] <- GRT$AGoalPerShots[8]
Model$AGoalPerShots[Model$Away == "Liverpool"] <- GRT$AGoalPerShots[9]
Model$AGoalPerShots[Model$Away == "Man City"] <- GRT$AGoalPerShots[10]
Model$AGoalPerShots[Model$Away == "Man United"] <- GRT$AGoalPerShots[11]
Model$AGoalPerShots[Model$Away == "Middlesbrough"] <- GRT$AGoalPerShots[12]
Model$AGoalPerShots[Model$Away == "Southampton"] <- GRT$AGoalPerShots[13]
Model$AGoalPerShots[Model$Away == "Stoke"] <- GRT$AGoalPerShots[14]
Model$AGoalPerShots[Model$Away == "Sunderland"] <- GRT$AGoalPerShots[15]
Model$AGoalPerShots[Model$Away == "Swansea"] <- GRT$AGoalPerShots[16]
Model$AGoalPerShots[Model$Away == "Tottenham"] <- GRT$AGoalPerShots[17]
Model$AGoalPerShots[Model$Away == "Watford"] <- GRT$AGoalPerShots[18]
Model$AGoalPerShots[Model$Away == "West Brom"] <- GRT$AGoalPerShots[19]
Model$AGoalPerShots[Model$Away == "West Ham" ] <- GRT$AGoalPerShots[20]
Model$HConcedePerShots[Model$Home == "Arsenal"] <- GRT$HConcedePerShots[1]
Model$HConcedePerShots[Model$Home == "Bournemouth"] <- GRT$HConcedePerShots[2]
Model$HConcedePerShots[Model$Home == "Burnley"] <- GRT$HConcedePerShots[3]
Model$HConcedePerShots[Model$Home == "Chelsea"] <- GRT$HConcedePerShots[4]
Model$HConcedePerShots[Model$Home == "Crystal Palace"] <- GRT$HConcedePerShots[5]
Model$HConcedePerShots[Model$Home == "Everton"] <- GRT$HConcedePerShots[6]
Model$HConcedePerShots[Model$Home == "Hull"] <- GRT$HConcedePerShots[7]
Model$HConcedePerShots[Model$Home == "Leicester"] <- GRT$HConcedePerShots[8]
Model$HConcedePerShots[Model$Home == "Liverpool"] <- GRT$HConcedePerShots[9]
Model$HConcedePerShots[Model$Home == "Man City"] <- GRT$HConcedePerShots[10]
Model$HConcedePerShots[Model$Home == "Man United"] <- GRT$HConcedePerShots[11]
Model$HConcedePerShots[Model$Home == "Middlesbrough"] <- GRT$HConcedePerShots[12]
Model$HConcedePerShots[Model$Home == "Southampton"] <- GRT$HConcedePerShots[13]
Model$HConcedePerShots[Model$Home == "Stoke"] <- GRT$HConcedePerShots[14]
Model$HConcedePerShots[Model$Home == "Sunderland"] <- GRT$HConcedePerShots[15]
Model$HConcedePerShots[Model$Home == "Swansea"] <- GRT$HConcedePerShots[16]
Model$HConcedePerShots[Model$Home == "Tottenham"] <- GRT$HConcedePerShots[17]
Model$HConcedePerShots[Model$Home == "Watford"] <- GRT$HConcedePerShots[18]
Model$HConcedePerShots[Model$Home == "West Brom"] <- GRT$HConcedePerShots[19]
Model$HConcedePerShots[Model$Home == "West Ham"] <- GRT$HConcedePerShots[20]
Model$AConcedePerShots[Model$Away == "Arsenal"] <- GRT$AConcedePerShots[1]
Model$AConcedePerShots[Model$Away == "Bournemouth"] <- GRT$AConcedePerShots[2]
Model$AConcedePerShots[Model$Away == "Burnley"] <- GRT$AConcedePerShots[3]
Model$AConcedePerShots[Model$Away == "Chelsea"] <- GRT$AConcedePerShots[4]
Model$AConcedePerShots[Model$Away == "Crystal Palace"] <- GRT$AConcedePerShots[5]
Model$AConcedePerShots[Model$Away == "Everton"] <- GRT$AConcedePerShots[6]
Model$AConcedePerShots[Model$Away == "Hull"] <- GRT$AConcedePerShots[7]
Model$AConcedePerShots[Model$Away == "Leicester"] <- GRT$AConcedePerShots[8]
Model$AConcedePerShots[Model$Away == "Liverpool"] <- GRT$AConcedePerShots[9]
Model$AConcedePerShots[Model$Away == "Man City"] <- GRT$AConcedePerShots[10]
Model$AConcedePerShots[Model$Away == "Man United"] <- GRT$AConcedePerShots[11]
Model$AConcedePerShots[Model$Away == "Middlesbrough"] <- GRT$AConcedePerShots[12]
Model$AConcedePerShots[Model$Away == "Southampton"] <- GRT$AConcedePerShots[13]
Model$AConcedePerShots[Model$Away == "Stoke"] <- GRT$AConcedePerShots[14]
Model$AConcedePerShots[Model$Away == "Sunderland"] <- GRT$AConcedePerShots[15]
Model$AConcedePerShots[Model$Away == "Swansea"] <- GRT$AConcedePerShots[16]
Model$AConcedePerShots[Model$Away == "Tottenham"] <- GRT$AConcedePerShots[17]
Model$AConcedePerShots[Model$Away == "Watford"] <- GRT$AConcedePerShots[18]
Model$AConcedePerShots[Model$Away == "West Brom"] <- GRT$AConcedePerShots[19]
Model$AConcedePerShots[Model$Away == "West Ham" ] <- GRT$AConcedePerShots[20]
Model$AverageHAShots[Model$Home == "Arsenal"] <- SoModel$AverageHAShots[1]
Model$AverageHAShots[Model$Home == "Bournemouth"] <- SoModel$AverageHAShots[2]
Model$AverageHAShots[Model$Home == "Burnley"] <- SoModel$AverageHAShots[3]
Model$AverageHAShots[Model$Home == "Chelsea"] <- SoModel$AverageHAShots[4]
Model$AverageHAShots[Model$Home == "Crystal Palace"] <- SoModel$AverageHAShots[5]
Model$AverageHAShots[Model$Home == "Everton"] <- SoModel$AverageHAShots[6]
Model$AverageHAShots[Model$Home == "Hull"] <- SoModel$AverageHAShots[7]
Model$AverageHAShots[Model$Home == "Leicester"] <- SoModel$AverageHAShots[8]
Model$AverageHAShots[Model$Home == "Liverpool"] <- SoModel$AverageHAShots[9]
Model$AverageHAShots[Model$Home == "Man City"] <- SoModel$AverageHAShots[10]
Model$AverageHAShots[Model$Home == "Man United"] <- SoModel$AverageHAShots[11]
Model$AverageHAShots[Model$Home == "Middlesbrough"] <- SoModel$AverageHAShots[12]
Model$AverageHAShots[Model$Home == "Southampton"] <- SoModel$AverageHAShots[13]
Model$AverageHAShots[Model$Home == "Stoke"] <- SoModel$AverageHAShots[14]
Model$AverageHAShots[Model$Home == "Sunderland"] <- SoModel$AverageHAShots[15]
Model$AverageHAShots[Model$Home == "Swansea"] <- SoModel$AverageHAShots[16]
Model$AverageHAShots[Model$Home == "Tottenham"] <- SoModel$AverageHAShots[17]
Model$AverageHAShots[Model$Home == "Watford"] <- SoModel$AverageHAShots[18]
Model$AverageHAShots[Model$Home == "West Brom"] <- SoModel$AverageHAShots[19]
Model$AverageHAShots[Model$Home == "West Ham"] <- SoModel$AverageHAShots[20]
Model$AverageAAShots[Model$Away == "Arsenal"] <- SoModel$AverageAAShots[1]
Model$AverageAAShots[Model$Away == "Bournemouth"] <- SoModel$AverageAAShots[2]
Model$AverageAAShots[Model$Away == "Burnley"] <- SoModel$AverageAAShots[3]
Model$AverageAAShots[Model$Away == "Chelsea"] <- SoModel$AverageAAShots[4]
Model$AverageAAShots[Model$Away == "Crystal Palace"] <- SoModel$AverageAAShots[5]
Model$AverageAAShots[Model$Away == "Everton"] <- SoModel$AverageAAShots[6]
Model$AverageAAShots[Model$Away == "Hull"] <- SoModel$AverageAAShots[7]
Model$AverageAAShots[Model$Away == "Leicester"] <- SoModel$AverageAAShots[8]
Model$AverageAAShots[Model$Away == "Liverpool"] <- SoModel$AverageAAShots[9]
Model$AverageAAShots[Model$Away == "Man City"] <- SoModel$AverageAAShots[10]
Model$AverageAAShots[Model$Away == "Man United"] <- SoModel$AverageAAShots[11]
Model$AverageAAShots[Model$Away == "Middlesbrough"] <- SoModel$AverageAAShots[12]
Model$AverageAAShots[Model$Away == "Southampton"] <- SoModel$AverageAAShots[13]
Model$AverageAAShots[Model$Away == "Stoke"] <- SoModel$AverageAAShots[14]
Model$AverageAAShots[Model$Away == "Sunderland"] <- SoModel$AverageAAShots[15]
Model$AverageAAShots[Model$Away == "Swansea"] <- SoModel$AverageAAShots[16]
Model$AverageAAShots[Model$Away == "Tottenham"] <- SoModel$AverageAAShots[17]
Model$AverageAAShots[Model$Away == "Watford"] <- SoModel$AverageAAShots[18]
Model$AverageAAShots[Model$Away == "West Brom"] <- SoModel$AverageAAShots[19]
Model$AverageAAShots[Model$Away == "West Ham" ] <- SoModel$AverageAAShots[20]
答案 0 :(得分:1)
假设我正确理解了数据的结构,我会尝试这样的事情:使用所有元素创建列表citylist
,而不是使用sapply
。然后你可以只替换最后一行中的变量名,或者创建第二个列表,在那里存储你想要使用的所有变量名并循环遍历它们。
#dummy data
Home <- c("Arsenal","Arsenal","Bournemouth","Bournemouth","Burnley","Burnley","Burnley","Chelsea")
Model <- data.frame(Home)
AttackHome <- c("something1","something2","something3","something4")
AP <- data.frame(AttackHome)
#create the list
citylist <- list("Arsenal"=1,"Bournemouth"=2,"Burnley"=3,"Chelsea"=4)
#use sapply
Model$AttackHome <- sapply(Model$Home,function(x) {AP$AttackHome[citylist[[x]]]})