[R] recoding one variable into another - but differently for different cases
Dimitri Liakhovitski
ld7631 at gmail.com
Tue Jan 22 18:25:58 CET 2008
Hello,
I have 2 variables in my sample Data: Data$A and Data$B
Variable Data$A can assume values: 1, 2, 3, and 4.
Variable Data$B identifies my cases and can assume values: 1 and 2.
I need to recode my variable Data$A into a new variable Data$new such that:
People who are Data[Data$B %in% 1, ] are recoded like this:
Value on Data$A Value on Data$new
1 +1
2 -1
3 0
4 99
People who are Data[Data$B %in% 2, ] are recoded like this:
Value on Data$A Value on Data$new
1 -1
2 +1
3 0
4 99
I am having hard time doing this. Any help would be greatly appreciated.
Dimitri
More information about the R-help
mailing list