Dear colleagues,

I want to calculate the value of x2 based on the value of x1.  x1 is a
factor with three separate levels. I want to make sure that missing
values remain as NA in X2, but non-missing values take on a value of
either 0  or 1 dependending on the value in x1.

This is the code I'm working with...Can any one help?
I've seen some other requests on a topic like this, but not using factors with strings as levels; only with numeric variables.
Simon

x1<-factor(levels="social and cultural specialists", "labour",
"salariat")

x2<-if(x1==c("social and cultural specialists")) "1" elseif (x1==NA)
"NA" else "0"
*********************************
Simon J. Kiss, PhD
SSHRC and DAAD Post-Doctoral Fellow
John F. Kennedy Institute of North America Studies
Free University of Berlin
Lansstraße 7-9
14195 Berlin, Germany
Cell: +49 (0)1525-300-2812,
Web: http://www.jfki.fu-berlin.de/index.html

______________________________________________
R-help@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.

Reply via email to