否则,如果梯子无法从给定的选项中进行选择

时间:2019-04-24 11:58:59

标签: r

我正在运行一个if if else阶梯,它应根据随机生成的变量(enctypef[1,1])从一系列表中进行选择,并在其中生成一个随机样本。

我对以这种方式使用R很陌生,并且使用switch函数也不能解决问题。将if else放在方括号中也可以避免R问题出现在不同的行上。 (这是为了产生地下城与龙日的旅行发电机。)

{
  if (enctypef[1,1] = 1) {
    print(charaenc[sample(nrow(charaenc),1, replace= TRUE), ])
} else if (enctypef[1,1] = 2) {
    print(fsocenc[sample(nrow(fsocenc),1, replace= TRUE), ])
} else if (enctypef[1,1] = 3) {
    print(hsocenc[sample(nrow(hsocenc),1, replace= TRUE), ])
} else if (enctypef[1,1] = 4) {
    print(skllchall[sample(nrow(skllchll),1, replace= TRUE), ])
} else if (enctypef[1,1] = 5) {
    print("Combat! (Non-commital)")
} else
print("Combat! (Aggressive!)")
}

我希望基于遇到类型为1:6的随机样本,它将在4个可用表上滚动或打印“ Combat!(Non-commital)” / Combat! (非承诺)。

我得到的错误如下:

>{
+   if (enctypef[1,1] = 1) {
Error: unexpected '=' in:
"{
  if (enctypef[1,1] ="
>     print(charaenc[sample(nrow(charaenc),1, replace= TRUE), ])
   d100                        Encounter
14   14 A place you would love to visit 
> } else if (enctypef[1,1] = 2) {
Error: unexpected '}' in "}"
>     print(fsocenc[sample(nrow(fsocenc),1, replace= TRUE), ])
  d20                                                           Encounter
5   5 An old woman needs your help to get an unusual pet down from a tree
> } else if (enctypef[1,1] = 3) {
Error: unexpected '}' in "}"
>     print(hsocenc[sample(nrow(hsocenc),1, replace= TRUE), ])
  d20                                                                                        Encounter
1   1 A group of racist thugs has an issue with one of your party members because of their appearance 
> } else if (enctypef[1,1] = 4) {
Error: unexpected '}' in "}"
>     print(skllchall[sample(nrow(skllchll),1, replace= TRUE), ])
Error in nrow(skllchll) : object 'skllchll' not found
> } else if (enctypef[1,1] = 5) {
Error: unexpected '}' in "}"
>     print("Combat! (Non-commital)")
[1] "Combat! (Non-commital)"
> } else
Error: unexpected '}' in "}"
> print(Combat! (Non-commital))
Error: unexpected '!' in "print(Combat!"
> }
Error: unexpected '}' in "}"

0 个答案:

没有答案