dimanche 8 octobre 2017

unexpected '<=' in IF statement R

I'm trying to create a function which depending of the value of x, returns one of two functions. When I creating the following function, I get an error and I have no idea why.

t <- c(0.1,0.9,1.5)

squeze <- function(x){
 if(t[1]<x<=t[2]){
  exp(a1*x+b1)
 } else {
  exp(a2*x+b2)
 }
} 

The error message:

Error: unexpected '<=' in:
"squeze <- function(x){
if(t[1]<x<="
> exp(a1*x+b1)
Error: object 'x' not found
> } else {
Error: unexpected '}' in "  }"
> exp(a2*x+b2)
Error: object 'x' not found
> }
Error: unexpected '}' in "  }"
> }
Error: unexpected '}' in "}"

I would highly appreciate if someone was able to point out what I have missed.

In advance, thank you!

Aucun commentaire:

Enregistrer un commentaire