Lucas Sousa
Lucas Sousa

Reputation: 3

How to create a function with a range in R?

I want to define the function f(x) = (2/pi) * sqrt(1-(x^2)) and its range [-1,1]. I don't think there's a Indicator Function in R, but how can I define this range?

Upvotes: 0

Views: 189

Answers (1)

ThomasIsCoding
ThomasIsCoding

Reputation: 102920

What about this kind of function definition?

f <- function(x) {
  stopifnot(abs(x)<=1)
  (2/pi) * sqrt(1-(x^2))
}

Upvotes: 1

Related Questions