I'm looking to create an binary variable column that shows simply indicates whether or not an existing column is equal to "R" or "P". If it is equal, i would like the new column to read "1", and if there is a blank observation I would like it to read "0".
I would like this:
Person Play Key
A 1 R
B 2 P
C 3
D 4 R
E 5
To become this:
Person Play Key Indicator
A 1 R 1
B 2 P 1
C 3 0
D 4 R 1
E 5 0
I have tried:
df$Indicator <- (df$Key == 'R' | 'P')
But that doesn't work. I get the error Error in df$Indicator <- (df$Key == 'R' | 'P')" : operations are possible only for numeric, logical or complex types
Besides I'm not sure that would provide the binary indicator I'm looking for.