[R-SIG-Mac] ifelse script

Duncan Murdoch murdoch.duncan at gmail.com
Wed Oct 25 19:23:43 CEST 2017


On 25/10/2017 1:18 PM, Jose G Conde Santiago via R-SIG-Mac wrote:
> Hello.
> 
> I got one new variable computed using ifelse through R Commander. The variable was created without a problem. This was the expression to compute:
> 
> ifelse(icdfrrcond1 == 1 | icdfrrcond2 == 1 | icdfrrcond3 == 1 | icdfrrcond4  == 1 | icdfrrcond5  == 1 | icdfrrcond6 == 1 | icdfrrcond7 == 1 | icdfrrcond8 == 1 | icdfrrcond9  == 1 | icdfrrcond10  == 1 | icdfrrcond11  == 1 | icdfrrcond12  == 1 | icdfrrcond13 == 1 |  icdfrrcond14  == 1 | icdfrrcond15   == 1 | icdfrrcond16 == 1 | icdfrrcond17  == 1 | icdfrrcond18 == 1 | icdfrrcond19  == 1 | icdfrrcond20  == 1, icdfrischhrtdis <- 1, icdfrischhrtdis <- 0)

That's not the way to use ifelse():  it's not a control sequence like 
"if (cond) ... else ...", it's a function.  You should write it as

icdfrischhrtdis <- ifelse(icdfrrcond1 == 1 | icdfrrcond2 == 1 | 
icdfrrcond3 == 1 | icdfrrcond4  == 1 | icdfrrcond5  == 1 | icdfrrcond6 
== 1 | icdfrrcond7 == 1 | icdfrrcond8 == 1 | icdfrrcond9  == 1 | 
icdfrrcond10  == 1 | icdfrrcond11  == 1 | icdfrrcond12  == 1 | 
icdfrrcond13 == 1 |  icdfrrcond14  == 1 | icdfrrcond15   == 1 | 
icdfrrcond16 == 1 | icdfrrcond17  == 1 | icdfrrcond18 == 1 | 
icdfrrcond19  == 1 | icdfrrcond20  == 1, 1, 0)

Duncan Murdoch

> 
> This is the script generated by R Commander:
> 
> mortprres0515sle$icdfrischhrtdis <- with(mortprres0515sle, ifelse(icdfrrcond1 ==   1 | icdfrrcond2 == 1 | icdfrrcond3 == 1 | icdfrrcond4  == 1 | icdfrrcond5  == 1 |   icdfrrcond6 == 1 | icdfrrcond7 == 1 | icdfrrcond8 == 1 | icdfrrcond9  == 1 |   icdfrrcond10  == 1 | icdfrrcond11  == 1 | icdfrrcond12  == 1 | icdfrrcond13 == 1   |  icdfrrcond14  == 1 | icdfrrcond15   == 1 | icdfrrcond16 == 1 | icdfrrcond17    == 1 | icdfrrcond18 == 1 | icdfrrcond19  == 1 | icdfrrcond20  == 1,   icdfrischhrtdis <- 1, icdfrischhrtdis <- 0))
> 
> When I try to run this same script from RStudio or the R console, the script is read, but the variable is not created. Even if I highlight the script in R Commander and “Submit” it, I get the same problem.
> 
> What I would like to do is to copy the script and modify it, so I can create 10 additional variables using just one script that I can run directly in R or RStudio.
> 
> Thanks.
> 
> José
>     
> 
> José G. Conde, MD, MPH
> Professor, School of Medicine
> Director, CentIT2
> UPR Medical Sciences Campus
> 
> Tel  (787) 763-9401 Fax (787) 758-5206
> 
> Email: jose.conde1 at upr.edu
> 
> URL: http://rcmi.rcm.upr.edu
> 
> _______________________________________________
> R-SIG-Mac mailing list
> R-SIG-Mac at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-mac
>



More information about the R-SIG-Mac mailing list