[R] Using if

Jeff Newmiller jdnewmil at dcn.davis.CA.us
Tue Nov 20 20:17:42 CET 2012


?ifelse

Quite distinct from if () {} else {}.
---------------------------------------------------------------------------
Jeff Newmiller                        The     .....       .....  Go Live...
DCN:<jdnewmil at dcn.davis.ca.us>        Basics: ##.#.       ##.#.  Live Go...
                                      Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/Batteries            O.O#.       #.O#.  with
/Software/Embedded Controllers)               .OO#.       .OO#.  rocks...1k
--------------------------------------------------------------------------- 
Sent from my phone. Please excuse my brevity.

Virgile Capo-Chichi <vcapochichi at gmail.com> wrote:

>Dear R users,
>
>As a new comer to R, I would like to create a new variable using if
>statements but don't know how to do it. Basically, I have two variables
>(EvHint and MinTex). I want to create a third variable called RiskTest.
>
>In SPSS, my syntax would look like
>
>Compute RiskTest=0.
>if (EvHint=1 & MinTex=1) RiskTest=1.
>
>Question: How do I do this with R?
>
>My Data
>
>EvHint<-c(0, 0, 0, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 0, 0, 1, 0, 0)
>MinTex<-c(0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0)
>
>Thanks, V
>
>	[[alternative HTML version deleted]]
>
>______________________________________________
>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.




More information about the R-help mailing list