Test3 <- function(n,d) {
die1 = sample(1:d, n, replace = TRUE)
die2 = sample(1:d, n, replace = TRUE)
move = die1 + die2
position_before_roll = move
position_after_roll = move
monopoly_sim = data.frame(position_before_roll, die1,die2,move,position_after_roll)
monopoly_sim[1,1]=0
#Needs to be position after roll + Dice Roll (Move)
monopoly_sim[n+1,1] = monopoly_sim[n,5]
return(monopoly_sim)
}
df = Test3(5,6)
x1= as.data.frame(df)
这是我的代码。我试图让我的position_before roll =到我之前的position_after_roll。
从那里有position_after_roll = position_before_roll + move。
我无法更新行。仅更新最后一行,因为它具有n + 1值(在这种情况下n = 5)