精華區beta R_Language 關於我們 聯絡資訊
※ 引述《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://www.ptt.cc/bbs/R_Language/M.1447686004.A.B69.html
celestialgod: 沒用過這招@@ 推 11/16 23:01