gpt4 book ai didi

r - 重复 else if 语句的快捷方式

转载 作者:行者123 更新时间:2023-12-02 06:28:08 25 4
gpt4 key购买 nike

如果条件如下,我必须重复编写 else:

  if (d_hand[1]==1){
state=score(p_hand)-1
} else if (d_hand[1]==2){
state=19+score(p_hand)
} else if (d_hand[1]==3){
state=39+score(p_hand)
} else if (d_hand[1]==4){
state=59+score(p_hand)
} else if (d_hand[1]==5){
state=79+score(p_hand)
} else if (d_hand[1]==6){
state=99+score(p_hand)
}

你知道它是否可以写得更高效/更短吗?我想过做一个 if 循环,但效率会降低,因为必须检查每个语句。

最佳答案

根本没有ifelse:

state <- score(p_hand) + 20 * d_hand[1] - 21

关于r - 重复 else if 语句的快捷方式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49676353/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com