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