Why it always gives me a 3?

> fun=function(x) {
+ if (x<-3) {
+ return(x) 
+ } else {
+ if(x<2) {
+ return(x^2-1)
+ } else {
+ return(log(x))
+ }}}
> 
> fun(-5)
[1] 3
> fun(0)
[1] 3
> fun(10)
[1] 3
> fun(-10)
[1] 3
> 



--
View this message in context: 
http://r.789695.n4.nabble.com/Problem-with-if-tp4649180.html
Sent from the R help mailing list archive at Nabble.com.

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to