R switch() how to compare cases to a vector?

后端 未结 4 569
自闭症患者
自闭症患者 2021-01-21 02:28

I\'ve got a little issue with the switch statement in R. The following code is OK ... :

    value = \"B\"
  switch(value, 
         \"A\"={
           print(\"         


        
4条回答
  •  旧巷少年郎
    2021-01-21 03:15

    Try using vapply.

    i.e. in your case

    vapply(mychr,switch,"",...SWITCH ARGS...)
    

    I think what you would want is:

    vapply(mychr,switch,"",
                   mychr[1]=mychr[1],mychr[2]=mychr[2],mychr[3]=mychr[3],"Other !!!")
    

提交回复
热议问题