[R] Using if

arun smartpink111 at yahoo.com
Tue Nov 20 21:02:23 CET 2012


HI,
May be this:
RiskTest<-ifelse(EvHint==1 & MinTex==1,1,0)
RiskTest
# [1] 0 0 0 1 0 1 1 0 0 0 0 1 0 0 0 0 0 0 0 0
A.K.




----- Original Message -----
From: Virgile Capo-Chichi <vcapochichi at gmail.com>
To: r-help at r-project.org
Cc: 
Sent: Tuesday, November 20, 2012 2:08 PM
Subject: [R] Using if

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