乡下人产国偷v产偷v自拍,国产午夜片在线观看,婷婷成人亚洲综合国产麻豆,久久综合给合久久狠狠狠9

  • <output id="e9wm2"></output>
    <s id="e9wm2"><nobr id="e9wm2"><ins id="e9wm2"></ins></nobr></s>

    • 分享

      R語言 If...Else語句

       imtravelinghah 2022-07-16 發(fā)布于廣西

      if語句后面可以是一個可選的else語句,當布爾表達式為false時執(zhí)行。

      語法

      在R中創(chuàng)建if ... else語句的基本語法是 -

      if(boolean_expression) {
         // statement(s) will execute if the boolean expression is true.
      } else {
         // statement(s) will execute if the boolean expression is false.
      }
      
      如果布爾表達式的計算結果為真,則將執(zhí)行if代碼塊,否則將執(zhí)行代碼塊。

      流程圖


      x <- c("what","is","truth")
      
      if("Truth" %in% x) {
         print("Truth is found")
      } else {
         print("Truth is not found")
      }
      

      當上面的代碼被編譯和執(zhí)行時,它產生以下結果 -
      [1] "Truth is not found"
      
      這里“Truth”和“truth”是兩個不同的字符串。

      if ... else if ... else語句

      if語句后面可以跟一個可選的else if ... else語句,這對于使用single if ... else if語句測試各種條件非常有用。

      當使用if,else if,else語句有幾點要記住。

      • 如果可以有零或一個else,它必須在任何其他if之后。
      • 一個if可以有0到許多else if和它們必須在else之前。
      • 一旦一個else如果成功,沒有任何剩余的else if或else將被測試。

      語法

      在R中創(chuàng)建if ... else if ... else語句的基本語法是 -

      if(boolean_expression 1) {
         // Executes when the boolean expression 1 is true.
      } else if( boolean_expression 2) {
         // Executes when the boolean expression 2 is true.
      } else if( boolean_expression 3) {
         // Executes when the boolean expression 3 is true.
      } else {
         // executes when none of the above condition is true.
      }
      

      x <- c("what","is","truth")
      
      if("Truth" %in% x) {
         print("Truth is found the first time")
      } else if ("truth" %in% x) {
         print("truth is found the second time")
      } else {
         print("No truth found")
      }
      
      當上面的代碼被編譯和執(zhí)行時,它產生以下結果 -
      [1] "truth is found the second time"
      

        本站是提供個人知識管理的網絡存儲空間,所有內容均由用戶發(fā)布,不代表本站觀點。請注意甄別內容中的聯系方式、誘導購買等信息,謹防詐騙。如發(fā)現有害或侵權內容,請點擊一鍵舉報。
        轉藏 分享 獻花(0

        0條評論

        發(fā)表

        請遵守用戶 評論公約

        類似文章 更多