Say I have multiple if conditions, under which different values are assigned to a variable. For instance:
x <- rep(c(1, 2, 3, 4, 5, 6, 7, 8), 4)
for(i in length(x)) {
if(x[i] == 2) {
x[i] <- 10
}
if(x[i] == 4) {
x[i] <- 12
}
## and there are more similar if conditions
## ......
}
In general, I'd like to replace the numbers in this vector with other numbers according to specific conditions. Is there a simpler way to do this without writing such a long loop?