[R] Translating recoding syntax from SPSS to R

arun smartpink111 at yahoo.com
Sun Sep 22 08:47:02 CEST 2013


Hi,
Try:
set.seed(429)
dat1<- data.frame(race=sample(1:3,20,replace=TRUE),usborn=sample(0:2,20,replace=TRUE))
 dat1$confused<- 1*((dat1$race==1|dat1$race==2) & dat1$usborn==0)
head(dat1)
#  race usborn confused
#1    3      2        0
#2    1      0        1
#3    2      1        0
#4    3      2        0
#5    1      2        0
#6    1      1        0
A.K.



----- Original Message -----
From: Mosi Ifatunji <ifatunji at gmail.com>
To: "r-help at r-project.org" <r-help at r-project.org>
Cc: 
Sent: Saturday, September 21, 2013 6:03 PM
Subject: [R] Translating recoding syntax from SPSS to R

Colleagues,

I am in the process of learning R. I've been able to import my dataset (from Stata) and do some simple coding. I have now come to coding situation that requires some assistance. This is some code in SPSS that I would like to be able to execute in R:

if (race eq 1 and usborn=0) confused=1 .
if (race eq 2 and usborn=0) confused=1 .
if (race eq 1 and usborn=1) confused=0 .
if (race eq 2 and usborn=1) confused=0 .
if (race eq 3 and usborn=1) confused=0 .
if (race eq 3 and cohort=1) confused=0 .
if (race eq 3 and cohort=2) confused=0 .
variable labels confused "R claims to be both an African American and foriegn born" .
value labels confused
    1 "Both AfAm and Foreign"
    2 "Not" .
select if (confused eq 0) .

Any assistance would be greatly appreciated.

-- Mosi
______________________________________________
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