R programming error missing value where TRUE FALSE needed

0 votes
My code
tfr<-function(x) {return (x[1]^2 + x[2]^2 + x[3]^2 <=1)}
monte_carlo<-function (test_fn, n,  x0=-1, y0=-1, z0=-1, x1=1, y1=1, z1=1)
{
  V_B<- ((x1-x0)*(y1-y0)*(z1-z0))
  k<-0
  for (I in 1:n)
  {
     x<- runif(2, min=c(x0,y0,z0), max=c(x1,y1,z1))  
    if (test_fn(x))
     { k<- k+1}
  }
  return (V_B*k/n)
}

at startup
> monte_carlo(tfr,100000)
gives out
Error in if (test_fn(x)) { : missing value where TRUE/FALSE needed
May 20, 2021 in Data Analytics by Kaktus

edited Mar 4, 2025 322 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP