在阐述我的问题的一个简单的方法,可以考虑我有以下功能:如果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")
我应该如何解决这个问题?