有没有办法在变量被更改之前存储它?
Is there a way to store a variable before it gets changed?
我对 R 还很陌生,我的第一个大项目是模拟当地 Quiz Bowl 锦标赛的季后赛。我得到了代码,因此它可以 运行 我想要的模拟次数,并且每次都打印出冠军。问题是,我无法找到一种方法将过去的冠军存储在任何地方,因为我正在使用重复功能,所以每次 R 通过我的模拟时,都会在变量 Champion 下设置一个新的冠军。我会放一些代码,希望能有所帮助。
Count <- 0
repeat {
Champion <-ifelse(Team37 > Team38 & Team37 > Team39,
Game13_T1,
ifelse(Team38 > Team39,
Game13_T2,
Game13_T3))
print(Champion)
Count = Count + 1
if (Count == 10000) {
break
}
}
所以,我需要一些方法来存储我所有的冠军,因为我想跟踪并创建冠军获胜概率等。在 repeat 之前以及 repeat 和我那里的下一行代码之间还有很多其他的胡言乱语,但我认为这应该能给你们所有的要点。非常感谢您的帮助!
我假设 Champion
将成为某个团队的名称,因此它将是字符类型。可以在开头初始化一个vector来存储每个Champion
。
Count <- 0
all_champion <- character(10000)
#If it's a number use numeric
#all_champion <- numeric(10000)
repeat {
Champion <- ifelse(Team37 > Team38 & Team37 > Team39, Game13_T1,
ifelse(Team38 > Team39, Game13_T2, Game13_T3))
Count = Count + 1
all_champion[Count] <- Champion
if (Count == 10000) {
break
}
}
我对 R 还很陌生,我的第一个大项目是模拟当地 Quiz Bowl 锦标赛的季后赛。我得到了代码,因此它可以 运行 我想要的模拟次数,并且每次都打印出冠军。问题是,我无法找到一种方法将过去的冠军存储在任何地方,因为我正在使用重复功能,所以每次 R 通过我的模拟时,都会在变量 Champion 下设置一个新的冠军。我会放一些代码,希望能有所帮助。
Count <- 0
repeat {
Champion <-ifelse(Team37 > Team38 & Team37 > Team39,
Game13_T1,
ifelse(Team38 > Team39,
Game13_T2,
Game13_T3))
print(Champion)
Count = Count + 1
if (Count == 10000) {
break
}
}
所以,我需要一些方法来存储我所有的冠军,因为我想跟踪并创建冠军获胜概率等。在 repeat 之前以及 repeat 和我那里的下一行代码之间还有很多其他的胡言乱语,但我认为这应该能给你们所有的要点。非常感谢您的帮助!
我假设 Champion
将成为某个团队的名称,因此它将是字符类型。可以在开头初始化一个vector来存储每个Champion
。
Count <- 0
all_champion <- character(10000)
#If it's a number use numeric
#all_champion <- numeric(10000)
repeat {
Champion <- ifelse(Team37 > Team38 & Team37 > Team39, Game13_T1,
ifelse(Team38 > Team39, Game13_T2, Game13_T3))
Count = Count + 1
all_champion[Count] <- Champion
if (Count == 10000) {
break
}
}