[R] Problem with if
David Winsemius
dwinsemius at comcast.net
Sat Nov 10 17:58:27 CET 2012
On Nov 10, 2012, at 8:34 AM, Haszun wrote:
> Why it always gives me a 3?
>
>> fun=function(x) {
> + if (x<-3) {
The above code assigns 3 to x.
> + 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 at 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.
David Winsemius, MD
Alameda, CA, USA
More information about the R-help
mailing list