在R,当我试图通过ifelse
分配的功能,我得到以下错误:为什么我不能在R中分配一个带有ifelse的函数?
> my.func <- ifelse(cond, sqrt, identity)
Error in rep(yes, length.out = length(ans)) :
attempt to replicate an object of type 'builtin'
如果cond
是FALSE
,错误看起来相当的,R抱怨的
attempt to replicate an object of type 'closure'
什么我可以做两个函数中的一个赋值给一个变量以及这里发生了什么?
对此问题予以启发,是关系到[这个问题](http://stackoverflow.com/questions/17685502 )。 – quazgar