I would like to convert a charter sequence into a numeric sequence.
My variable is called labCancer and is made like this:
labCancer
[1] M M M M M M M M M M M M M M M M M M M B B B M M M M M M M M M M M M M M M B
I would like to have:
[1] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 1 1 1 1 1 1 1 1 1 1 0
I tried using
labCancer_2 <- labCancer
for (i in 1:569) {
if (labCancer[i] == "M") {
labCancer_2[i] <- 1
} else {
labCancer_2[i] <- 2
} }
but it doesn't work.
Andrea