On 4/17/07, Luca Braglia <[EMAIL PROTECTED]> wrote:
>
> I have found a strange "ifelse" behaviour (I think)
Don't you think it is rather consistent behavior?
> ifelse(T,1+1,1+2)
[1] 2
> ifelse(F,1+1,1+2)
[1] 3
> ifelse(T,"hello","goodbye")
[1] "hello"
> ifelse(F,"hello","goodbye")
[1] "goodbye"
> ifelse(T,print("hello"),print("goodbye"))
[1] "hello"
[1] "hello"
> ifelse(F,print("hello"),print("goodbye"))
[1] "goodbye"
[1] "goodbye"
> ifelse(T,print(1+1),print(1+2))
[1] 2
[1] 2
> ifelse(F,print(1+1),print(1+2))
[1] 3
[1] 3
This works:
>
> > ifelse(T,1+1,1+2)
> [1] 2
> > ifelse(F,1+1,1+2)
> [1] 3
>
> Maybe I missed something about R internals, but why
>
> > ifelse(T,print("hello"),print("goodbye"))
> [1] "hello"
> [1] "hello"
> > ifelse(F,print("hello"),print("goodbye"))
> [1] "goodbye"
> [1] "goodbye"
>
> values are returned two times? I'm not sure: if it's a bug I'll post it
> immediately
>
> Thank You
>
> Luca
>
>
> Version:
> platform = i486-pc-linux-gnu
> arch = i486
> os = linux-gnu
> system = i486, linux-gnu
> status =
> major = 2
> minor = 4.1
> year = 2006
> month = 12
> day = 18
> svn rev = 40228
> language = R
> version.string = R version 2.4.1 (2006-12-18)
>
> Locale:
>
> LC_CTYPE=it_IT.UTF-8;LC_NUMERIC=C;LC_TIME=it_IT.UTF-8;LC_COLLATE=it_IT.UTF-8;LC_MONETARY=it_IT.UTF-8;LC_MESSAGES=it_IT.UTF-8;LC_PAPER=it_IT.UTF-8;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=it_IT.UTF-8;LC_IDENTIFICATION=C
>
> Search Path:
> .GlobalEnv, package:MASS, package:utils, package:stats, package:graphics,
> package:grDevices, package:methods, Autoloads, package:base
>
> ______________________________________________
> [email protected] 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.
>
[[alternative HTML version deleted]]
______________________________________________
[email protected] 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.