I have a list of data with results that include numbers and also include text.
Example data:
df$col_1
Neg
Negative
32
16
64
8
128
4
not done
Pos
Missing
?Pos
~2
? 240
What I have done is create a new column and try to re-code the data.
df$col <- NA df$col [ which (df$col_1=="Positive" )] <- 1
df$col [ which (df$col_1=="2" )] <- 1
df$col [ which (df$col_1=="Negative" )] <- 1
Rather than coding every possible combination, as above, What I would like to do is be able to create a list of negatives, positives and NA values.
I tried this
list <- c ("2","4","8","16","32")
df$col [ which (df$col_1=="list" )] <- 1
But this did not work.
Every number should be considered positive, unless there is a question mark. So I wondered whether I could convert all numbers to numeric?
For all the miscellaneous text, other than positive and negative, I want to put NA.
df$col_1 df$col
Neg 0
Negative 0
32 1
16 1
64 1
8 1
128 1
4 1
not done NA
Pos 1
Missing NA
?Pos NA
~2 1
? 240 NA