Skip to content

Problem with if

3 messages · Haszun, David Winsemius, Patrick Burns

#
Why it always gives me a 3?
+ if (x<-3) {
+ return(x) 
+ } else {
+ if(x<2) {
+ return(x^2-1)
+ } else {
+ return(log(x))
+ }}}
[1] 3
[1] 3
[1] 3
[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.
#
On Nov 10, 2012, at 8:34 AM, Haszun wrote:

            
The above code assigns 3 to x.
David Winsemius, MD
Alameda, CA, USA
#
This is Circle 8.1.30 of 'The R Inferno'.

http://www.burns-stat.com/pages/Tutor/R_inferno.pdf

The example even uses 3.
On 10/11/2012 16:58, David Winsemius wrote: