在闡述我的問題的一個簡單的方法,可以考慮我有以下功能:如果R中數組聲明
> ff<-function(a){ if (a>0){ return ("positive") } else{ return("negative") } }
現在
:
> ff(-1)
[1] "negative"
> ff(1)
[1] "positive"
而當使用一個數組:
> print(ff(c(-1,1)))
[1] "negative" "negative"
Warning message:
In if (a > 0) { :
the condition has length > 1 and only the first element will be used
我期待
print(ff(c(-1,1)))=("negative" "positive")
我應該如何解決這個問題?