5
A
回答
11
的if
构建体仅考虑当载体被传递给它的第一组分,(并给出一个警告)
if(sample(100,10)>50)
print("first component greater 50")
else
print("first component less/equal 50")
的ifelse
功能执行每个部件上的检查,并返回一个矢量
ifelse(sample(100,10)>50, "greater 50", "less/equal 50")
例如,ifelse
函数对于transform
很有用。 使用&
或|
在ifelse
条件和&&
或||
在if
通常是有用的。
9
回答你的第二个部分:
* 使用if
当x为1长度,但使y是大于1 *
x <- 4
y <- c(8, 10, 12, 3, 17)
if (x < y) x else y
[1] 8 10 12 3 17
Warning message:
In if (x < y) x else y :
the condition has length > 1 and only the first element will be used
使用ifelse
当x有长度为1但y的长度大于1
ifelse (x < y,x,y)
[1] 4 4 4 3 4
相关问题
- 1. if-else vs ifelse with lists
- 2. if-else vs if-else-if-else
- 3. Lookup Table vs if-else
- 4. 嵌套if-else vs if-else?
- 5. if..else vs if(){return}
- 6. tryCatch()Vs if else
- 7. switch case vs if else
- 8. if/else vs ternary operator
- 9. C#if else vs if或vs switch case
- 10. Python 3 and-or vs if-else
- 11. 模式匹配vs if-else
- 12. PHP exit()vs if - else语句
- 13. try/catch vs if/else throw NullPointerException
- 14. 使用IF ... ELSE VS如果()
- 15. if/ifelse问题
- 16. if-> return vs if-> else效率
- 17. 是if elseif ifif possible vs if else?
- 18. if/if else/else
- 19. if else else if sql
- 20. Javascript if if else else
- 21. 两个条件如何在if-ifelse-else语句中起作用?
- 22. 使用if(。){} else {} lapply
- 23. if else if else in angular js
- 24. if,else,else if and end Lua
- 25. if/else if/else menu issue c
- 26. jQuery if if else else filter
- 27. jQuery/Javascript if if contains else else
- 28. If Else If Else sort XSLT1.0
- 29. if else if else语句(JS)
- 30. while if else else
这是超级有趣。我可能会认为它是一个缺点,如果我试图比较一个int和列表,我更喜欢得到一个警告 –