R語言中if判斷語句


 

1、測試1

num = 8
if (num %% 2 == 0) { print("even!") }

 

 

2、測試2

num = 7
if (num %% 2 == 0) { print("even!") }

 

3、測試3

num = 7
if (num %% 2 == 0) { print("even!") } else { print("odd!") }

 

4、測試4

for (i in 1:10) { if (i %% 2 == 0) { print(i) } }

 

5、測試5

score <- 88
if (score >= 0 & score < 60) { print("failed") } else
if (score >= 60 & score < 70) { print("pass") } else
if (score >= 70 & score < 90) { print("brilliant") } else
if (score >= 90 & score <= 100) { print("excellant!") } else { print("input error") }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM