mardi 9 février 2021

Defining a piecewise function with if and else statements in Rstudio

Disclaimer as I am extremly new. I am trying to make a piecewise function but I get the error that a symbol is wrong? What am I doing wrong. Help is much appreciated!

g<-function(x){if ( x < 0) {
  0
  } else if ( x <= 1) {
  x^2
  } else if ( x >= 0) {
  x^2
  } else {
  2x-1
  }
}

Aucun commentaire:

Enregistrer un commentaire