Hello everybody!
I have again a rather simple question concerning recoding of variables:
I have a variable/data-frame column BIRTHPLACE containing abbreviations of
the 26 swiss counties (AG, AI, AR, BE, ZH, ... )
as well as international country codes (USA, GER, ESP, etc.) and another
variable RES_STA indicating the
residence status (A, B, C, X, Y)
My goal is now to create a new variable VARNEW under the following
conditions:
- should be the RESIDENCE_STATUS
- except:
- if RESIDENCE_STATUS is X and at the same time BIRTHPLACE is one of
the 26
swiss counties then it should be "swiss"
- otherweise it should be "unknown"
I have already tried the following code:
mydata$VARNEW<-mydata$RESIDENCE_STATUS # setting VARNEW as
RESIDENCE_STATUS
idx<-(mydata$RESIDENCE_STATUS=="X" && !( # TRUE: unknown; FALSE:
swiss
mydata$BIRTHPLACE=="AG" |
mydata$BIRTHPLACE=="BE" |
mydata$BIRTHPLACE=="AR"
...
)
)
and then?
Thank you for any help!
David
[[alternative HTML version deleted]]
______________________________________________
[email protected] 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.