switch() statement usage

后端 未结 2 1749
傲寒
傲寒 2020-12-04 07:42

I am a little confused about the switch statement in R. Simply googling the function I get an example as follows:

A common use of switch is to branch according to t

2条回答
  •  一生所求
    2020-12-04 08:35

    In short, yes. But there are times when you might favor one vs. the other. Google "case switch vs. if else". There are some discussions already on SO too. Also, here is a good video that talks about it in the context of MATLAB:

    http://blogs.mathworks.com/pick/2008/01/02/matlab-basics-switch-case-vs-if-elseif/

    Personally, when I have 3 or more cases, I usually just go with case/switch.

提交回复
热议问题