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, ]
Dimitri Liakhovitski wrote:
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:
You could create a lookup table or use recode in the car package.
Another possibility is to use a logical/arithmetic expression. The
following expression says that
- if A is 1 then use the first term equals the coefficient, namely 1
if B ==1 and -1 if B == 2.
Also, if A is not 1 then that
Slight correction of the English:
- if A is 1 then the first term equals the coefficient of (A == 1).
That is the first term equals 1 if B==1 and equals -1 if B==2.
If A does not equal 1 then the first term is zero and can be ignored.
- terms 2 and 3 are interpreted analogously
- if A==3 (or
Thanks a lot, everyone!
Dimitri
On 1/22/08, Gabor Grothendieck [EMAIL PROTECTED] wrote:
Slight correction of the English:
- if A is 1 then the first term equals the coefficient of (A == 1).
That is the first term equals 1 if B==1 and equals -1 if B==2.
If A does not equal 1 then the first
No one else mentioned this, but if those 99s represent missings, you
should be using NA not a special numeric value.
Hadley
On Jan 22, 2008 5:40 PM, Dimitri Liakhovitski [EMAIL PROTECTED] wrote:
Thanks a lot, everyone!
Dimitri
On 1/22/08, Gabor Grothendieck [EMAIL PROTECTED] wrote:
Slight
On 23/01/2008, at 2:02 PM, hadley wickham wrote:
No one else mentioned this, but if those 99s represent missings, you
should be using NA not a special numeric value.
Amen, bro. Using ``99'' to represent a missing value is
a heinous, if all too often inflicted, crime against
Note that if you do use NA rather than 99 as others have suggested then
the A==4 term should use ifelse rather than multiplication since 0 *
NA = NA, not 0:
transform(Data, new =
(A == 1) * ((B == 1) - (B == 2)) + (A == 2) * ((B == 2) - (B ==1))
+ ifelse(A == 4, NA, 0))
In fact, although more
8 matches
Mail list logo