「R言語」if~else if文のサンプル

書式
if(boolean_expression 1) {
// 条件式 1 の場合、処理コードを実行する
} else if( boolean_expression 2) {
// 条件式 2 の場合、処理コードを実行する
} else if( boolean_expression 3) {
// 条件式 3 の場合、処理コードを実行する
} else {
// 条件式以外の場合
}
使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
tt <- c("google","arkgame","yahoo")
if("facebook" %in% tt) {
print("1番目のif文にfacebookが含まれる")
} else if ("arkgame" %in% tt) {
print("2番目のif文にarkgameが含まれる")
} else {
print("見当たりません")
}
tt <- c("google","arkgame","yahoo") if("facebook" %in% tt) { print("1番目のif文にfacebookが含まれる") } else if ("arkgame" %in% tt) { print("2番目のif文にarkgameが含まれる") } else { print("見当たりません") }
tt <- c("google","arkgame","yahoo")

if("facebook" %in% tt) {
   print("1番目のif文にfacebookが含まれる")
} else if ("arkgame" %in% tt) {
   print("2番目のif文にarkgameが含まれる")
} else {
   print("見当たりません")
}

実行結果
[1] “2番目のif文にarkgameが含まれる"

R言語

Posted by arkgame