9
We need to know if your variable is a factor. Suppose
foo <- c("yes","no","no","yes")
If is.factor(foo) returns TRUE, e.g., if you did foo <- factor(foo), then use
levels(foo) <- c("2", "1")
else use
foo[foo == "yes"] <- 1
foo[foo == "no"] <- 2
Also, list() doesn't do what (I think) you think it does. If you want to view the value of foo, just type in foo. After executing the code above...
foo
[1] 1 2 2 1