作者Wush978 (拒看低质媒体)
看板R_Language
标题Re: [问题] 关於switch选择
时间Mon Nov 16 23:00:01 2015
※ 引述《laputaca (离歌笑)》之铭言:
: [问题叙述]:
: 在function里面使用switch时
: [程式范例]:
: 比如说我想要
: 当fruit=apple
: x=x[,2]
: y=y[,2]
: fruit=grape
: x=x[,3]
: y=y[,3]
: 则写成程式
: data = function(x, fruit)
: {
: switch(fruit, apple=????
: grape=????这个地方完全就不知道怎麽打... )
: }
: if else又只能用在数字...
: 还是说除了switch之外,有其他[名词]条件选择的指令呢?
: 感谢各位大大
可以用 `{`
switch(fruit,
"apple" = {
# do what you want
},
"grape" = {
# do what you want
})
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 118.161.31.173
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/R_Language/M.1447686004.A.B69.html
1F:推 celestialgod: 没用过这招@@ 推 11/16 23:01