I am running the code below. The function Ax returtns the value 1. But the ifelse statement does not recognize that Ax==1.
I've tried making the output of the function double-precision and all numeric values double. This hasn't worked.
I was hoping:
1) to get help troubleshooting this specific case
2) to get tips on how to avoid this problem in the future
Axfun<-function(beta,gamma,a,b,g,H0stud,Wh,Wi){
((b*beta + g*gamma)*(1 + 2*g*gamma)*(1 + gamma + b*((-beta)*(1 + gamma) + a*(-1 + beta)*(1 + g*gamma)))*H0stud*Wi)/
((-1 + b*beta)*(1 + gamma)*((-g)*gamma*(1 + 2*g*gamma)*Wi + b*beta*((-1 + g*gamma*(-2 + H0stud) + H0stud)*Wh - (1 + g*gamma)*H0stud*Wi)))
}
Ax<-Axfun(2^1,
2^0,
2^0,
2^-3,
2^-1,
1,
1,
0.4)
ifelse(Ax>=1, 0, Ax)
There is nothing wrong with the
>=
, your problem is that 1 is not really one. Try thisand
Edit: A possible Solution
As solutions to your problems you can return the final result of your function to an object and then use it as the
ceiling
function.If you have to work with such results maybe a read of the Circle 1 of the R Inferno is a good thing to do. You can find it here.